Skip to content

Commit 8112eb5

Browse files
authored
Merge pull request #247 from Ebrukoksal/patch-1
Add weighted sampling function to weighted_ebru_koksal.py
2 parents 35f892f + ce8c3df commit 8112eb5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Week02/weighted_ebru_koksal.py

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

0 commit comments

Comments
 (0)