From 48ecdbfbb27d575e828c7b788cb511507e7aaf9d Mon Sep 17 00:00:00 2001 From: UmuTurk230315070 <230315070@ogr.cbu.edu.tr> Date: Sun, 16 Mar 2025 23:05:33 +0300 Subject: [PATCH 1/2] Create weighted_umut_turk.py --- Week03/weighted_umut_turk.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Week03/weighted_umut_turk.py diff --git a/Week03/weighted_umut_turk.py b/Week03/weighted_umut_turk.py new file mode 100644 index 0000000..9046b86 --- /dev/null +++ b/Week03/weighted_umut_turk.py @@ -0,0 +1,14 @@ +import random +def weighted_srs(data, n, weights, with_replacement): + 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) From 47e9b3c1b92be3b95ace6b0014f092c36dd8ac96 Mon Sep 17 00:00:00 2001 From: UmuTurk230315070 <230315070@ogr.cbu.edu.tr> Date: Thu, 3 Apr 2025 22:17:59 +0300 Subject: [PATCH 2/2] Update weighted_umut_turk.py --- Week03/weighted_umut_turk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week03/weighted_umut_turk.py b/Week03/weighted_umut_turk.py index 9046b86..983d7e8 100644 --- a/Week03/weighted_umut_turk.py +++ b/Week03/weighted_umut_turk.py @@ -1,5 +1,5 @@ import random -def weighted_srs(data, n, weights, with_replacement): +def weighted_srs(data, n, weights, with_replacement = False): weighted_data = [] # Weighted list of data a = 0 for x in data: