diff --git a/Week03/weighted_umut_turk.py b/Week03/weighted_umut_turk.py new file mode 100644 index 0000000..983d7e8 --- /dev/null +++ b/Week03/weighted_umut_turk.py @@ -0,0 +1,14 @@ +import random +def weighted_srs(data, n, weights, with_replacement = False): + weighted_data = [] # Weighted list of data + a = 0 + for x in data: + b = 0 + while b < weights[a]: + weighted_data.append(x) # Adds the data weight times into the weighted list + b+=1 + a+=1 + if with_replacement: + return random.choices(weighted_data, k = n) + else: + return random.sample(weighted_data , k = n)