Skip to content

Commit 8d271d4

Browse files
authored
Merge pull request #91 from EeivorR/patch-2
Create weighted_tufan_sengel.py
2 parents 020c488 + 23fa7a7 commit 8d271d4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Week03/weighted_tufan_sengel.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import random
2+
3+
def weighted_srs(data, n, weights, with_replacement = False):
4+
if(with_replacement):
5+
sample = random.choices(data, weights=weights, k=n)
6+
else:
7+
sample = random.sample(data, n, counts=weights)
8+
return sample

0 commit comments

Comments
 (0)