We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 003e9b6 + 578a735 commit 35f892fCopy full SHA for 35f892f
Week02/weighted_riza_arslan.py
@@ -0,0 +1,8 @@
1
+import random
2
+def weighted_srs(data, n, weights, with_replacement=False):
3
+ w = weights if weights else [1]*len(data)
4
+ if with_replacement or weights:
5
+ return random.choices(data, weights=w, k=n)
6
+ res, d_c = [], list(data)
7
+ for _ in range(n): res.append(d_c.pop(random.randrange(len(d_c))))
8
+ return res
0 commit comments