Skip to content

Commit 35f892f

Browse files
authored
Merge pull request #246 from ragg211/master
weighted_riza_arslan.py
2 parents 003e9b6 + 578a735 commit 35f892f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Week02/weighted_riza_arslan.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)