diff --git a/Week02/weighted_batuhan_keskin.py b/Week02/weighted_batuhan_keskin.py new file mode 100644 index 00000000..6ced0192 --- /dev/null +++ b/Week02/weighted_batuhan_keskin.py @@ -0,0 +1,6 @@ +import random + +def weighted_srs(data, n, weights, with_replacement=False): + if with_replacement: return random.choices(data, weights=weights, k=n) # sample with replacement + if not weights: return random.sample(data, n) # simple random sample without weights + return random.sample(data, n, counts=weights) # sample without replacement using weights as counts