Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Week03/weighted_umut_turk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import random
def weighted_srs(data, n, weights, with_replacement = False):
weighted_data = [] # Weighted list of data
a = 0
for x in data:
b = 0
while b < weights[a]:
weighted_data.append(x) # Adds the data weight times into the weighted list
b+=1
a+=1
if with_replacement:
return random.choices(weighted_data, k = n)
else:
return random.sample(weighted_data , k = n)
Loading