generated from microsoft/python-package-template
-
Notifications
You must be signed in to change notification settings - Fork 16
/
samples.jsonl
2192 lines (2192 loc) · 591 KB
/
samples.jsonl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{"task_id": "DSP/0", "completion": "def get_string(x,y):\n return str(x)+str(y)\n raise NotImplementedError()"}
{"task_id": "DSP/0", "completion": "def get_string(x,y):\n return str(x)+str(y)\n raise NotImplementedError()"}
{"task_id": "DSP/1", "completion": "def ypolynomial(x,p):\n if x > 0:\n return 4 + 5*x**p\n else: \n return 0\n raise NotImplementedError()"}
{"task_id": "DSP/1", "completion": "def ypolynomial(x,p):\n if x > 0:\n return 4 + 5*x**p\n else: \n return 0\n raise NotImplementedError()"}
{"task_id": "DSP/2", "completion": "def isObesse(weight, height):\n if weight/height**2 >= 30:\n return 'obese'\n else:\n return 'not obese'\n raise NotImplementedError()"}
{"task_id": "DSP/2", "completion": "def isObesse(weight, height):\n if weight/height**2 >= 30:\n return 'obese'\n else:\n return 'not obese'\n raise NotImplementedError()"}
{"task_id": "DSP/3", "completion": "def divisibles(N, p):\n result = []\n if N < 0:\n N=20\n else:\n pass\n \n i = 0\n while i <= N:\n if i%p == 0:\n result.append(i)\n else:\n pass\n i+=1\n return result\n raise NotImplementedError()"}
{"task_id": "DSP/3", "completion": "def divisibles(N, p):\n result = []\n if N < 0:\n N=20\n else:\n pass\n \n i = 0\n while i <= N:\n if i%p == 0:\n result.append(i)\n else:\n pass\n i+=1\n return result\n raise NotImplementedError()"}
{"task_id": "DSP/4", "completion": "def removeDuplicates(mylist):\n return list(np.unique(np.array(mylist)))\n raise NotImplementedError()"}
{"task_id": "DSP/4", "completion": "def removeDuplicates(mylist):\n return list(np.unique(np.array(mylist)))\n raise NotImplementedError()"}
{"task_id": "DSP/5", "completion": "def sumOfFirstAndLast(listx):\n if len(listx) == 0:\n return 0\n else:\n return listx[0] + listx[-1]\n raise NotImplementedError()"}
{"task_id": "DSP/5", "completion": "def sumOfFirstAndLast(listx):\n if len(listx) == 0:\n return 0\n else:\n return listx[0] + listx[-1]\n raise NotImplementedError()"}
{"task_id": "DSP/6", "completion": "def sumDigits(number):\n listn = [int(i) for i in str(number)]\n x = 0\n for n in listn:\n x+=n\n return x\n raise NotImplementedError()"}
{"task_id": "DSP/6", "completion": "def sumDigits(number):\n listn = [int(i) for i in str(number)]\n x = 0\n for n in listn:\n x+=n\n return x\n raise NotImplementedError()"}
{"task_id": "DSP/7", "completion": "def countEvenDigits(number):\n listn = [int(i) for i in str(number)]\n count = 0\n for i in listn:\n if i%2 == 0:\n count+=1\n else:\n pass\n return count\n raise NotImplementedError()"}
{"task_id": "DSP/7", "completion": "def countEvenDigits(number):\n listn = [int(i) for i in str(number)]\n count = 0\n for i in listn:\n if i%2 == 0:\n count+=1\n else:\n pass\n return count\n raise NotImplementedError()"}
{"task_id": "DSP/8", "completion": "def countOddEvenDigits(number):\n listn = [int(i) for i in str(number)]\n count_odd = 0\n count_even = 0\n for i in listn:\n if i%2 == 0:\n count_even+=1\n else:\n count_odd+=1\n return {'odd':count_odd, 'even':count_even}\n raise NotImplementedError()"}
{"task_id": "DSP/8", "completion": "def countOddEvenDigits(number):\n listn = [int(i) for i in str(number)]\n count_odd = 0\n count_even = 0\n for i in listn:\n if i%2 == 0:\n count_even+=1\n else:\n count_odd+=1\n return {'odd':count_odd, 'even':count_even}\n raise NotImplementedError()"}
{"task_id": "DSP/9", "completion": "def verify_ISBN13(ISBN):\n isbn = str(ISBN)\n ev = sum([int(i) for i in isbn[::2]])\n od = 3*sum([int(i) for i in isbn[1::2]])\n if 0 == (od + ev) % 10:\n return \"Valid\"\n else:\n return \"Invalid\"\n raise NotImplementedError()"}
{"task_id": "DSP/9", "completion": "def verify_ISBN13(ISBN):\n isbn = str(ISBN)\n ev = sum([int(i) for i in isbn[::2]])\n od = 3*sum([int(i) for i in isbn[1::2]])\n if 0 == (od + ev) % 10:\n return \"Valid\"\n else:\n return \"Invalid\"\n raise NotImplementedError()"}
{"task_id": "DSP/10", "completion": "floating_bubbles=1.6180339# YOUR CODE HERE"}
{"task_id": "DSP/10", "completion": "floating_bubbles=1.6180339# YOUR CODE HERE"}
{"task_id": "DSP/11", "completion": "the_string='Spamelot'# YOUR CODE HERE"}
{"task_id": "DSP/11", "completion": "the_string='Spamelot'# YOUR CODE HERE"}
{"task_id": "DSP/12", "completion": "square_root=math.sqrt(490490)# YOUR CODE HERE"}
{"task_id": "DSP/12", "completion": "square_root=math.sqrt(490490)# YOUR CODE HERE"}
{"task_id": "DSP/13", "completion": "sphere_radius=4.9# YOUR CODE HERE"}
{"task_id": "DSP/13", "completion": "sphere_radius=4.9# YOUR CODE HERE"}
{"task_id": "DSP/14", "completion": "sphere_volume = 4 / 3 * math.pi * sphere_radius ** 3 # YOUR CODE HERE"}
{"task_id": "DSP/14", "completion": "sphere_volume = 4 / 3 * math.pi * sphere_radius ** 3 # YOUR CODE HERE"}
{"task_id": "DSP/15", "completion": "the_volume_string = str(int(sphere_volume)) # YOUR CODE HERE"}
{"task_id": "DSP/15", "completion": "the_volume_string = str(int(sphere_volume)) # YOUR CODE HERE"}
{"task_id": "DSP/16", "completion": "def return_Weather(w):\n '''\n Takes a Weather object and returns the data contained within as a tuple\n \n Parameters\n ----------\n w: a weather object\n \n Returns\n -------\n a tuple\n '''\n # YOUR CODE HERE\n # return a tuple of data contained in a Weather object\n return (w.inch, w.ft, w.temp)"}
{"task_id": "DSP/16", "completion": "def return_Weather(w):\n '''\n Takes a Weather object and returns the data contained within as a tuple\n \n Parameters\n ----------\n w: a weather object\n \n Returns\n -------\n a tuple\n '''\n # YOUR CODE HERE\n # return a tuple of data contained in a Weather object\n return (w.inch, w.ft, w.temp)"}
{"task_id": "DSP/17", "completion": "def fix_inch(w):\n '''\n Takes a weather object and changes the \"inch\" attribute so that it does\n not contain 12 or more inches in it, modifying the \"ft\" attribute in the \n process. It then returns the weather object.\n \n Parameters\n ----------\n a Weather object\n \n Returns\n -------\n a Weather object\n '''\n # YOUR CODE HERE\n # If w.inch contains 12 or more inches\n if w.inch >= 12:\n # add proper amount to w.ft\n w.ft = w.ft + w.inch // 12\n # modify w.inch\n w.inch = w.inch % 12\n return w"}
{"task_id": "DSP/17", "completion": "def fix_inch(w):\n '''\n Takes a weather object and changes the \"inch\" attribute so that it does\n not contain 12 or more inches in it, modifying the \"ft\" attribute in the \n process. It then returns the weather object.\n \n Parameters\n ----------\n a Weather object\n \n Returns\n -------\n a Weather object\n '''\n # YOUR CODE HERE\n # If w.inch contains 12 or more inches\n if w.inch >= 12:\n # add proper amount to w.ft\n w.ft = w.ft + w.inch // 12\n # modify w.inch\n w.inch = w.inch % 12\n return w"}
{"task_id": "DSP/18", "completion": "def add_dat(w, inch, feet, temp):\n '''\n Adds inches and feet to a weather object, and changes the temperature of the \n weather object to a new temperature.\n \n Parameters\n ----------\n w: a weather object\n inch: an integer\n feet: an integer\n temp: an integer\n \n Returns\n -------\n A Weather object\n '''\n # YOUR CODE HERE\n # Adds inches and feet to the weather object\n w.inch = w.inch + inch\n w.ft = w.ft + feet\n # changes the temperature of the weather object to a new temperature.\n w.temp = temp\n # fix the inch\n fix_inch(w)\n return w"}
{"task_id": "DSP/18", "completion": "def add_dat(w, inch, feet, temp):\n '''\n Adds inches and feet to a weather object, and changes the temperature of the \n weather object to a new temperature.\n \n Parameters\n ----------\n w: a weather object\n inch: an integer\n feet: an integer\n temp: an integer\n \n Returns\n -------\n A Weather object\n '''\n # YOUR CODE HERE\n # Adds inches and feet to the weather object\n w.inch = w.inch + inch\n w.ft = w.ft + feet\n # changes the temperature of the weather object to a new temperature.\n w.temp = temp\n # fix the inch\n fix_inch(w)\n return w"}
{"task_id": "DSP/19", "completion": "class Circle:\n \n \"\"\"\n A class for representing a circle\n \n Parameters\n ----------\n radius: the circle's radius\n \n \"\"\"\n def __init__(self, radius):\n \n # assign the radius to itself\n self.radius = radius\n # create an attribute for diameter\n self.diameter = 2 * radius\n # create an attribute for area\n self.area = 3.141592653589793 * radius * radius"}
{"task_id": "DSP/19", "completion": "class Circle:\n \n \"\"\"\n A class for representing a circle\n \n Parameters\n ----------\n radius: the circle's radius\n \n \"\"\"\n def __init__(self, radius):\n \n # assign the radius to itself\n self.radius = radius\n # create an attribute for diameter\n self.diameter = 2 * radius\n # create an attribute for area\n self.area = 3.141592653589793 * radius * radius"}
{"task_id": "DSP/20", "completion": "class Circle2(Circle):\n \n \"\"\"\n A new class for representing a circle\n \n Parameters\n ----------\n radius: the circle's radius\n \n \"\"\"\n def plot(self, xlim, ylim):\n \n fig, ax = plt.subplots()\n # plot the circle\n c = plt.Circle((0,0), self.radius)\n # add it to the plot\n ax.add_patch(c)\n # set x limit\n ax.set_xlim(xlim)\n # set y limit\n ax.set_ylim(ylim)\n return ax"}
{"task_id": "DSP/20", "completion": "class Circle2(Circle):\n \n \"\"\"\n A new class for representing a circle\n \n Parameters\n ----------\n radius: the circle's radius\n \n \"\"\"\n def plot(self, xlim, ylim):\n \n fig, ax = plt.subplots()\n # plot the circle\n c = plt.Circle((0,0), self.radius)\n # add it to the plot\n ax.add_patch(c)\n # set x limit\n ax.set_xlim(xlim)\n # set y limit\n ax.set_ylim(ylim)\n return ax"}
{"task_id": "DSP/21", "completion": "def count_code_cells(filename, cell_type):\n '''\n Takes a filename and a cell type, and returns the number count of that cell type.\n \n Parameters\n ----------\n filename (str): a JSON file.\n cell_type (str): \"code\", \"markdown\", etc.\n \n Returns\n -------\n An int.\n '''\n # YOUR CODE HERE\n count = 0\n # Open the file\n with open(filename, 'r') as jsonfile:\n # Read the data\n data = json.load(jsonfile)\n # Get cell\n for cell in data['cells']:\n # Count the specific cell_type\n if cell[\"cell_type\"] == cell_type:\n count +=1\n\n return count"}
{"task_id": "DSP/21", "completion": "def count_code_cells(filename, cell_type):\n '''\n Takes a filename and a cell type, and returns the number count of that cell type.\n \n Parameters\n ----------\n filename (str): a JSON file.\n cell_type (str): \"code\", \"markdown\", etc.\n \n Returns\n -------\n An int.\n '''\n # YOUR CODE HERE\n count = 0\n # Open the file\n with open(filename, 'r') as jsonfile:\n # Read the data\n data = json.load(jsonfile)\n # Get cell\n for cell in data['cells']:\n # Count the specific cell_type\n if cell[\"cell_type\"] == cell_type:\n count +=1\n\n return count"}
{"task_id": "DSP/22", "completion": "def get_column(filename, n, header=True):\n '''\n Returns a list from reading the specified column in the CSV file.\n\n Parameters\n __________\n filename (str): Input file name. The file is assumed to be in a \n Comma Separated Values (CSV) format with latin-1 encoding.\n n (int): Column number. The first column starts at 0. The column must be\n a list of integers.\n header (bool): If True, the first line of file is column names.\n Default: True.\n '''\n result = []\n\n # YOUR CODE HERE\n import csv\n with open(filename, 'r', encoding = 'latin-1') as csvfile:\n for row in csv.reader(csvfile):\n apd = row[n]\n if header: #if header = True, skip the first row.\n header = False\n continue\n if apd != 'NA':\n result.append(int(apd))\n return result"}
{"task_id": "DSP/22", "completion": "def get_column(filename, n, header=True):\n '''\n Returns a list from reading the specified column in the CSV file.\n\n Parameters\n __________\n filename (str): Input file name. The file is assumed to be in a \n Comma Separated Values (CSV) format with latin-1 encoding.\n n (int): Column number. The first column starts at 0. The column must be\n a list of integers.\n header (bool): If True, the first line of file is column names.\n Default: True.\n '''\n result = []\n\n # YOUR CODE HERE\n import csv\n with open(filename, 'r', encoding = 'latin-1') as csvfile:\n for row in csv.reader(csvfile):\n apd = row[n]\n if header: #if header = True, skip the first row.\n header = False\n continue\n if apd != 'NA':\n result.append(int(apd))\n return result"}
{"task_id": "DSP/23", "completion": "def get_city(xml):\n \"\"\"\n Takes an XML and returns the city name.\n \n Parameters\n ----------\n xml (str): An XML script.\n \n Returns\n -------\n A string.\n \"\"\"\n # YOUR CODE HERE\n # Create a Beautifulsoup object\n soup = BeautifulSoup(xml, 'xml')\n soup.prettify()\n # Return the city name\n result = soup.City.string\n return result"}
{"task_id": "DSP/23", "completion": "def get_city(xml):\n \"\"\"\n Takes an XML and returns the city name.\n \n Parameters\n ----------\n xml (str): An XML script.\n \n Returns\n -------\n A string.\n \"\"\"\n # YOUR CODE HERE\n # Create a Beautifulsoup object\n soup = BeautifulSoup(xml, 'xml')\n soup.prettify()\n # Return the city name\n result = soup.City.string\n return result"}
{"task_id": "DSP/24", "completion": "def get_temp(xml):\n \"\"\"\n Takes an XML and returns the temperature.\n \n Parameters\n ----------\n xml (str): An XML script.\n \n Returns\n -------\n A float.\n \"\"\"\n # YOUR CODE HERE\n # Create a Beautifulsoup object\n soup = BeautifulSoup(xml, 'xml')\n soup.prettify()\n # Return the temperature\n result = float(soup.Temp.string[0:4])\n return result"}
{"task_id": "DSP/24", "completion": "def get_temp(xml):\n \"\"\"\n Takes an XML and returns the temperature.\n \n Parameters\n ----------\n xml (str): An XML script.\n \n Returns\n -------\n A float.\n \"\"\"\n # YOUR CODE HERE\n # Create a Beautifulsoup object\n soup = BeautifulSoup(xml, 'xml')\n soup.prettify()\n # Return the temperature\n result = float(soup.Temp.string[0:4])\n return result"}
{"task_id": "DSP/25", "completion": "def dict_from_lists(keys, values):\n '''\n Constructs a dictionary using the first input list as keys and second as values.\n \n Parameters\n __________\n keys: A list.\n values: A list.\n \n Returns\n _______\n output: A dictionary.\n '''\n # YOUR CODE HERE\n return dict(zip(keys, values))"}
{"task_id": "DSP/25", "completion": "def dict_from_lists(keys, values):\n '''\n Constructs a dictionary using the first input list as keys and second as values.\n \n Parameters\n __________\n keys: A list.\n values: A list.\n \n Returns\n _______\n output: A dictionary.\n '''\n # YOUR CODE HERE\n return dict(zip(keys, values))"}
{"task_id": "DSP/26", "completion": "def add_one(d, to_add):\n '''\n Adds the second dictionary to the first dictionary.\n \n Parameters\n __________\n d: A dictionary.\n to_add: A dictionary that will be added to d.\n \n Returns\n _______\n output: The updated dictionary d. \n '''\n # YOUR CODE HERE\n for key in to_add:\n d[key] = to_add[key]\n return d"}
{"task_id": "DSP/26", "completion": "def add_one(d, to_add):\n '''\n Adds the second dictionary to the first dictionary.\n \n Parameters\n __________\n d: A dictionary.\n to_add: A dictionary that will be added to d.\n \n Returns\n _______\n output: The updated dictionary d. \n '''\n # YOUR CODE HERE\n for key in to_add:\n d[key] = to_add[key]\n return d"}
{"task_id": "DSP/27", "completion": "def add_many(d, *dicts_to_add):\n '''\n Adds many dictionaries to the first dictionary.\n \n Parameters\n __________\n d: A dictionary.\n *dicts_to_add: Arbitrary number of dictionaries (1 or more dictionaries) that will be added to d.\n \n Returns\n _______\n output: The updated dictionary d. \n '''\n # YOUR CODE HERE\n for add in dicts_to_add:\n d = add_one(d, add)\n return d"}
{"task_id": "DSP/27", "completion": "def add_many(d, *dicts_to_add):\n '''\n Adds many dictionaries to the first dictionary.\n \n Parameters\n __________\n d: A dictionary.\n *dicts_to_add: Arbitrary number of dictionaries (1 or more dictionaries) that will be added to d.\n \n Returns\n _______\n output: The updated dictionary d. \n '''\n # YOUR CODE HERE\n for add in dicts_to_add:\n d = add_one(d, add)\n return d"}
{"task_id": "DSP/28", "completion": "def remove(d, to_remove):\n '''\n Removes the second dictionary from the first dictionary. \n \n Parameters\n __________\n d: A dicionary.\n to_remove: A dictionary that will be removed from d. \n \n Returns\n _______\n output: The updated dictionary d. \n '''\n # YOUR CODE HERE\n for key, value in to_remove.items():\n if key in d and d[key] == value:\n del d[key]\n return d"}
{"task_id": "DSP/28", "completion": "def remove(d, to_remove):\n '''\n Removes the second dictionary from the first dictionary. \n \n Parameters\n __________\n d: A dicionary.\n to_remove: A dictionary that will be removed from d. \n \n Returns\n _______\n output: The updated dictionary d. \n '''\n # YOUR CODE HERE\n for key, value in to_remove.items():\n if key in d and d[key] == value:\n del d[key]\n return d"}
{"task_id": "DSP/29", "completion": "eeveelution = dict_from_lists(names, types)\neeveelution = add_many(eeveelution, generationII, generationIV, generationVI)\neeveelution = remove(eeveelution, {\"Pikachu\": \"Electric\"})"}
{"task_id": "DSP/29", "completion": "eeveelution = dict_from_lists(names, types)\neeveelution = add_many(eeveelution, generationII, generationIV, generationVI)\neeveelution = remove(eeveelution, {\"Pikachu\": \"Electric\"})"}
{"task_id": "DSP/30", "completion": "def slice_string(a_string, ind1, ind2):\n # YOUR CODE HERE\n return a_string[ind1:ind2]"}
{"task_id": "DSP/30", "completion": "def slice_string(a_string, ind1, ind2):\n # YOUR CODE HERE\n return a_string[ind1:ind2]"}
{"task_id": "DSP/31", "completion": "def is_in(a_string, letter):\n # YOUR CODE HERE\n return letter in a_string"}
{"task_id": "DSP/31", "completion": "def is_in(a_string, letter):\n # YOUR CODE HERE\n return letter in a_string"}
{"task_id": "DSP/32", "completion": "def list_output(a_string, letter, ind1, ind2):\n # YOUR CODE HERE\n if letter in a_string:\n answer = 'Yes'\n else:\n answer = 'No'\n return 'The string is '+ a_string + '. Is the letter '+ letter + ' inside the string? ' + answer +'. The slice of the string is ' + a_string[ind1:ind2] + '.'"}
{"task_id": "DSP/32", "completion": "def list_output(a_string, letter, ind1, ind2):\n # YOUR CODE HERE\n if letter in a_string:\n answer = 'Yes'\n else:\n answer = 'No'\n return 'The string is '+ a_string + '. Is the letter '+ letter + ' inside the string? ' + answer +'. The slice of the string is ' + a_string[ind1:ind2] + '.'"}
{"task_id": "DSP/33", "completion": "def in_radians(degrees):\n # YOUR CODE HERE\n return math.pi * (degrees / 180)"}
{"task_id": "DSP/33", "completion": "def in_radians(degrees):\n # YOUR CODE HERE\n return math.pi * (degrees / 180)"}
{"task_id": "DSP/34", "completion": "def sine_of(degrees):\n # YOUR CODE HERE\n return math.sin(in_radians(degrees))"}
{"task_id": "DSP/34", "completion": "def sine_of(degrees):\n # YOUR CODE HERE\n return math.sin(in_radians(degrees))"}
{"task_id": "DSP/35", "completion": "def find_opp(degrees, hypo):\n # YOUR CODE HERE\n return hypo * sine_of(degrees)"}
{"task_id": "DSP/35", "completion": "def find_opp(degrees, hypo):\n # YOUR CODE HERE\n return hypo * sine_of(degrees)"}
{"task_id": "DSP/36", "completion": "def remove_hashtags(words):\n '''\n Take a list of strings.\n Returns a list of strings, where we discard all strings that are hashtags.\n \n Parameters\n ----------\n words: A list of strings.\n \n Returns\n -------\n A list of strings. None of the strings in the return list has a hashtag.\n '''\n # YOUR CODE HERE\n # Substitues every word in words that contains a # with an empty string '' using list comprehension\n words = [re.sub('\\#.*', '', word) for word in words]\n # Use filter to remove all empty strings\n words = list(filter(None, words))\n return words"}
{"task_id": "DSP/36", "completion": "def remove_hashtags(words):\n '''\n Take a list of strings.\n Returns a list of strings, where we discard all strings that are hashtags.\n \n Parameters\n ----------\n words: A list of strings.\n \n Returns\n -------\n A list of strings. None of the strings in the return list has a hashtag.\n '''\n # YOUR CODE HERE\n # Substitues every word in words that contains a # with an empty string '' using list comprehension\n words = [re.sub('\\#.*', '', word) for word in words]\n # Use filter to remove all empty strings\n words = list(filter(None, words))\n return words"}
{"task_id": "DSP/37", "completion": "def remove_users(words):\n '''\n Take a list of strings.\n Returns a list of strings, where we discard all strings that represent users.\n \n Parameters\n ----------\n words: A list of strings.\n \n Returns\n -------\n A list of strings. None of the strings in the return list has user tags.\n '''\n # YOUR CODE HERE\n # Substitues every word in words that contains a @ with an empty string ''\n words = [re.sub('@.*', '', word) for word in words]\n # Use filter to remove all empty strings\n words = list(filter(None, words))\n return words"}
{"task_id": "DSP/37", "completion": "def remove_users(words):\n '''\n Take a list of strings.\n Returns a list of strings, where we discard all strings that represent users.\n \n Parameters\n ----------\n words: A list of strings.\n \n Returns\n -------\n A list of strings. None of the strings in the return list has user tags.\n '''\n # YOUR CODE HERE\n # Substitues every word in words that contains a @ with an empty string ''\n words = [re.sub('@.*', '', word) for word in words]\n # Use filter to remove all empty strings\n words = list(filter(None, words))\n return words"}
{"task_id": "DSP/38", "completion": "def remove_links(words):\n '''\n Take a list of strings.\n Returns a list of strings, where we discard all strings that are http links.\n \n Parameters\n ----------\n words: A list of strings.\n \n Returns\n -------\n A list of strings. None of the strings in the return list is an http link.\n '''\n # YOUR CODE HERE\n # Substitues every word in words that contains 'http:' or 'https:' with an empty string ''\n words = [re.sub('https?:.*', '', word) for word in words]\n # Use filter to remove all empty strings\n words = list(filter(None, words))\n return words"}
{"task_id": "DSP/38", "completion": "def remove_links(words):\n '''\n Take a list of strings.\n Returns a list of strings, where we discard all strings that are http links.\n \n Parameters\n ----------\n words: A list of strings.\n \n Returns\n -------\n A list of strings. None of the strings in the return list is an http link.\n '''\n # YOUR CODE HERE\n # Substitues every word in words that contains 'http:' or 'https:' with an empty string ''\n words = [re.sub('https?:.*', '', word) for word in words]\n # Use filter to remove all empty strings\n words = list(filter(None, words))\n return words"}
{"task_id": "DSP/39", "completion": "def keep_letters(words):\n '''\n Take a list of strings.\n Returns a list of strings, where all strings have only alphabetical characters.\n \n Parameters\n ----------\n words: A list of strings.\n \n Returns\n -------\n A list of strings. None of the strings in the return list has any non-alphabetical characters.\n '''\n # YOUR CODE HERE\n # Substitues every non-alphabetical characters in words with an empty string ''\n words = [re.sub('[^A-Za-z]', '', word) for word in words]\n # Use filter to remove all empty strings\n words = list(filter(None, words))\n return words"}
{"task_id": "DSP/39", "completion": "def keep_letters(words):\n '''\n Take a list of strings.\n Returns a list of strings, where all strings have only alphabetical characters.\n \n Parameters\n ----------\n words: A list of strings.\n \n Returns\n -------\n A list of strings. None of the strings in the return list has any non-alphabetical characters.\n '''\n # YOUR CODE HERE\n # Substitues every non-alphabetical characters in words with an empty string ''\n words = [re.sub('[^A-Za-z]', '', word) for word in words]\n # Use filter to remove all empty strings\n words = list(filter(None, words))\n return words"}
{"task_id": "DSP/40", "completion": "def to_lower(words):\n '''\n Take a list of strings.\n Returns a list of strings, where all strings are lowercase.\n \n Parameters\n ----------\n words: A list of strings.\n \n Returns\n -------\n A list of strings. None of the strings in the return list has any capital letters.\n '''\n # YOUR CODE HERE\n # Convert all strings to lowercase with string method .lower()\n words = [word.lower() for word in words]\n return words"}
{"task_id": "DSP/40", "completion": "def to_lower(words):\n '''\n Take a list of strings.\n Returns a list of strings, where all strings are lowercase.\n \n Parameters\n ----------\n words: A list of strings.\n \n Returns\n -------\n A list of strings. None of the strings in the return list has any capital letters.\n '''\n # YOUR CODE HERE\n # Convert all strings to lowercase with string method .lower()\n words = [word.lower() for word in words]\n return words"}
{"task_id": "DSP/41", "completion": "def gen_cosine(n):\n standard_deviation = 0.2\n x = np.linspace(0, 2*math.pi, n)\n t = np.random.normal(np.cos(x), standard_deviation)\n return x, t"}
{"task_id": "DSP/41", "completion": "def gen_cosine(n):\n standard_deviation = 0.2\n x = np.linspace(0, 2*math.pi, n)\n t = np.random.normal(np.cos(x), standard_deviation)\n return x, t"}
{"task_id": "DSP/42", "completion": "def designmatrix(x, M): # it is highly recommended to write a helper function that computes Phi\n Phi = numpy.array([\n np.array([x[i]**j for j in range(M+1)])\n for i in range(x.shape[0])\n ])\n return Phi\n\ndef fit_polynomial(x, t, M):\n Phi = designmatrix(x, M)\n Phi_inv = np.linalg.pinv(Phi)\n w_ml = np.dot(Phi_inv, t)\n return w_ml, Phi"}
{"task_id": "DSP/42", "completion": "def designmatrix(x, M): # it is highly recommended to write a helper function that computes Phi\n Phi = numpy.array([\n np.array([x[i]**j for j in range(M+1)])\n for i in range(x.shape[0])\n ])\n return Phi\n\ndef fit_polynomial(x, t, M):\n Phi = designmatrix(x, M)\n Phi_inv = np.linalg.pinv(Phi)\n w_ml = np.dot(Phi_inv, t)\n return w_ml, Phi"}
{"task_id": "DSP/43", "completion": "def fit_polynomial_reg(x, t, m, lamb):\n Phi = designmatrix(x, m)\n Phi_sq = np.dot(Phi.T, Phi)\n inv_term = np.linalg.inv(lamb * np.identity(len(Phi_sq)) + Phi_sq)\n w_ml = np.dot(np.dot(inv_term, Phi.T), t)\n return w_ml, Phi"}
{"task_id": "DSP/43", "completion": "def fit_polynomial_reg(x, t, m, lamb):\n Phi = designmatrix(x, m)\n Phi_sq = np.dot(Phi.T, Phi)\n inv_term = np.linalg.inv(lamb * np.identity(len(Phi_sq)) + Phi_sq)\n w_ml = np.dot(np.dot(inv_term, Phi.T), t)\n return w_ml, Phi"}
{"task_id": "DSP/44", "completion": "def pred_error(x_train, x_valid, t_train, t_valid, M, lamb):\n w_ml, Phi_train = fit_polynomial_reg(x_train, t_train, M, lamb)\n \n Phi_valid = designmatrix(x_valid, M)\n y_valid = np.dot(Phi_valid, w_ml)\n\n diff = y_valid - t_valid\n pred_err = np.dot(np.transpose(diff), diff)\n return pred_err"}
{"task_id": "DSP/44", "completion": "def pred_error(x_train, x_valid, t_train, t_valid, M, lamb):\n w_ml, Phi_train = fit_polynomial_reg(x_train, t_train, M, lamb)\n \n Phi_valid = designmatrix(x_valid, M)\n y_valid = np.dot(Phi_valid, w_ml)\n\n diff = y_valid - t_valid\n pred_err = np.dot(np.transpose(diff), diff)\n return pred_err"}
{"task_id": "DSP/45", "completion": "def gen_cosine2(N):\n standard_deviation = 0.2\n x = np.random.uniform(0, 2*math.pi, N)\n x = np.sort(x)\n t = np.random.normal(np.cos(x), standard_deviation)\n return x, t"}
{"task_id": "DSP/45", "completion": "def gen_cosine2(N):\n standard_deviation = 0.2\n x = np.random.uniform(0, 2*math.pi, N)\n x = np.sort(x)\n t = np.random.normal(np.cos(x), standard_deviation)\n return x, t"}
{"task_id": "DSP/46", "completion": "def fit_polynomial_bayes(x, t, M, alpha, beta):\n Phi = designmatrix(x, M)\n Phi_sq = np.dot(Phi.T, Phi)\n S = np.linalg.inv(alpha * np.identity(len(Phi_sq)) + beta * Phi_sq)\n m = np.dot(np.dot(beta * S, Phi.T), t)\n \n return m, S, Phi"}
{"task_id": "DSP/46", "completion": "def fit_polynomial_bayes(x, t, M, alpha, beta):\n Phi = designmatrix(x, M)\n Phi_sq = np.dot(Phi.T, Phi)\n S = np.linalg.inv(alpha * np.identity(len(Phi_sq)) + beta * Phi_sq)\n m = np.dot(np.dot(beta * S, Phi.T), t)\n \n return m, S, Phi"}
{"task_id": "DSP/47", "completion": "def predict_polynomial_bayes(x, m, S, beta):\n Phi = designmatrix(x, len(m)-1)\n \n variance = np.array([1 / beta + np.dot(np.dot(phi.T, S), phi) for phi in Phi]) \n mean = np.dot(Phi, m.T)\n\n return mean, variance, Phi"}
{"task_id": "DSP/47", "completion": "def predict_polynomial_bayes(x, m, S, beta):\n Phi = designmatrix(x, len(m)-1)\n \n variance = np.array([1 / beta + np.dot(np.dot(phi.T, S), phi) for phi in Phi]) \n mean = np.dot(Phi, m.T)\n\n return mean, variance, Phi"}
{"task_id": "DSP/48", "completion": "import matplotlib.pyplot as plt\nimport pandas as pd\nimport numpy as np\nimport seaborn as sns\n\nimport sklearn.datasets\nimport sklearn.feature_selection\n\nfrom sklearn.datasets import fetch_olivetti_faces\nfrom sklearn.feature_selection import SelectPercentile\nfrom sklearn.feature_selection import chi2\n\nfaces = fetch_olivetti_faces()\n\nplt.matshow(faces.data[0].reshape((64,64)))\nplt.colorbar()\nplt.show()\n\nX = faces.data\ny = faces.target\n\np75 = SelectPercentile(score_func=chi2, percentile=25)\nX_new = p75.fit_transform(faces.data, faces.target)\nreshaped = np.reshape(p75.scores_, (64, 64))\n\nplt.matshow(reshaped)\nplt.colorbar()\nplt.show()\n\nsns.heatmap(reshaped, cbar=True)\nplt.show()"}
{"task_id": "DSP/48", "completion": "import matplotlib.pyplot as plt\nimport pandas as pd\nimport numpy as np\nimport seaborn as sns\n\nimport sklearn.datasets\nimport sklearn.feature_selection\n\nfrom sklearn.datasets import fetch_olivetti_faces\nfrom sklearn.feature_selection import SelectPercentile\nfrom sklearn.feature_selection import chi2\n\nfaces = fetch_olivetti_faces()\n\nplt.matshow(faces.data[0].reshape((64,64)))\nplt.colorbar()\nplt.show()\n\nX = faces.data\ny = faces.target\n\np75 = SelectPercentile(score_func=chi2, percentile=25)\nX_new = p75.fit_transform(faces.data, faces.target)\nreshaped = np.reshape(p75.scores_, (64, 64))\n\nplt.matshow(reshaped)\nplt.colorbar()\nplt.show()\n\nsns.heatmap(reshaped, cbar=True)\nplt.show()"}
{"task_id": "DSP/49", "completion": "from sklearn import datasets\nfrom sklearn.discriminant_analysis import LinearDiscriminantAnalysis\n\ndigits = datasets.load_digits()\n\nX = digits.data\ny = digits.target\n \nX_new = TSNE(n_components=2, perplexity=150, random_state=0).fit_transform(X)\nkmeans = KMeans(n_clusters=10, random_state=0).fit(X_new)\ny_new = kmeans.labels_\nscore = adjusted_rand_score(y, y_new)"}
{"task_id": "DSP/49", "completion": "from sklearn import datasets\nfrom sklearn.discriminant_analysis import LinearDiscriminantAnalysis\n\ndigits = datasets.load_digits()\n\nX = digits.data\ny = digits.target\n \nX_new = TSNE(n_components=2, perplexity=150, random_state=0).fit_transform(X)\nkmeans = KMeans(n_clusters=10, random_state=0).fit(X_new)\ny_new = kmeans.labels_\nscore = adjusted_rand_score(y, y_new)"}
{"task_id": "DSP/50", "completion": "import pandas as pd\nimport numpy as np\n\n# Load the ames dataset into a pandas dataframe\n# Make sure to save as \"ames_data\"\n\names_data = pd.read_table(\"ames_train.csv\", sep=\",\")\n\n# You can make sure you loaded it correctly by looking at its first few rows, using the .head() function\nprint(ames_data.head())"}
{"task_id": "DSP/50", "completion": "import pandas as pd\nimport numpy as np\n\n# Load the ames dataset into a pandas dataframe\n# Make sure to save as \"ames_data\"\n\names_data = pd.read_table(\"ames_train.csv\", sep=\",\")\n\n# You can make sure you loaded it correctly by looking at its first few rows, using the .head() function\nprint(ames_data.head())"}
{"task_id": "DSP/51", "completion": "ames_data[\"sqft_sum\"] = ames_data[\"1stFlrSF\"] + ames_data[\"2ndFlrSF\"]\n\names_data = ames_data[((ames_data.sqft_sum > 4000) & (ames_data.SalePrice < 300000)) != True]"}
{"task_id": "DSP/51", "completion": "ames_data[\"sqft_sum\"] = ames_data[\"1stFlrSF\"] + ames_data[\"2ndFlrSF\"]\n\names_data = ames_data[((ames_data.sqft_sum > 4000) & (ames_data.SalePrice < 300000)) != True]"}
{"task_id": "DSP/52", "completion": "from sklearn.model_selection import train_test_split\n\nX = ames_data[[\"sqft_sum\", \"Fireplaces\"]]\n\ny = ames_data[\"SalePrice\"]\n\n# Now we will split your data into training and test, for evaluation\n# Note the function below\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state=12323)"}
{"task_id": "DSP/52", "completion": "from sklearn.model_selection import train_test_split\n\nX = ames_data[[\"sqft_sum\", \"Fireplaces\"]]\n\ny = ames_data[\"SalePrice\"]\n\n# Now we will split your data into training and test, for evaluation\n# Note the function below\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state=12323)"}
{"task_id": "DSP/53", "completion": "from sklearn.linear_model import LinearRegression\nfrom sklearn.metrics import mean_squared_error\n\nlr = LinearRegression()\nlr.fit(X_train, y_train)\n\ny_preds = lr.predict(X_test)\n\nrmse = np.sqrt(mean_squared_error(y_preds, y_test))"}
{"task_id": "DSP/53", "completion": "from sklearn.linear_model import LinearRegression\nfrom sklearn.metrics import mean_squared_error\n\nlr = LinearRegression()\nlr.fit(X_train, y_train)\n\ny_preds = lr.predict(X_test)\n\nrmse = np.sqrt(mean_squared_error(y_preds, y_test))"}
{"task_id": "DSP/54", "completion": "def bootstrap(boot_pop, statistic, resample, replicates = 1000):\n \"\"\"\n Args:\n boot_pop: an array of shape n x d.\n statistic: a function which takes boot_pop and returns a number.\n resample: a function which takes n and returns a random sample from the integers [0, n)\n \n Return\n an array of length replicates, each entry being the statistic computed on a bootstrap sample of the data.\n \"\"\"\n \n return np.array([statistic(np.array([boot_pop[i] for i in resample(boot_pop.shape[0])])) for j in np.arange(replicates)])"}
{"task_id": "DSP/54", "completion": "def bootstrap(boot_pop, statistic, resample, replicates = 1000):\n \"\"\"\n Args:\n boot_pop: an array of shape n x d.\n statistic: a function which takes boot_pop and returns a number.\n resample: a function which takes n and returns a random sample from the integers [0, n)\n \n Return\n an array of length replicates, each entry being the statistic computed on a bootstrap sample of the data.\n \"\"\"\n \n return np.array([statistic(np.array([boot_pop[i] for i in resample(boot_pop.shape[0])])) for j in np.arange(replicates)])"}
{"task_id": "DSP/55", "completion": "replicates = 1000\nboot_theta = bootstrap(d, estimator, simple_resample, replicates)"}
{"task_id": "DSP/55", "completion": "replicates = 1000\nboot_theta = bootstrap(d, estimator, simple_resample, replicates)"}
{"task_id": "DSP/56", "completion": "def model(theta, total_bill):\n \"\"\"\n Takes the parameter theta and the total bill returns the computed tip.\n \"\"\"\n ...\n return theta * total_bill"}
{"task_id": "DSP/56", "completion": "def model(theta, total_bill):\n \"\"\"\n Takes the parameter theta and the total bill returns the computed tip.\n \"\"\"\n ...\n return theta * total_bill"}
{"task_id": "DSP/57", "completion": "def squared_loss(y_obs, y_hat):\n \"\"\"\n y_obs: an array of observed valued\n y_hat: an array of predicted values\n return an array corresponding to the loss for each prediction\n \"\"\"\n ...\n return (y_obs - y_hat)**2"}
{"task_id": "DSP/57", "completion": "def squared_loss(y_obs, y_hat):\n \"\"\"\n y_obs: an array of observed valued\n y_hat: an array of predicted values\n return an array corresponding to the loss for each prediction\n \"\"\"\n ...\n return (y_obs - y_hat)**2"}
{"task_id": "DSP/58", "completion": "loss = np.array([squared_loss(y, model(theta,x)).mean() for theta in thetas])"}
{"task_id": "DSP/58", "completion": "loss = np.array([squared_loss(y, model(theta,x)).mean() for theta in thetas])"}
{"task_id": "DSP/59", "completion": "def abs_loss(y_obs, y_hat):\n \"\"\"\n y_obs: an array of observed valued\n y_hat: an array of predicted values\n return an array corresponding to the loss for each prediction\n \"\"\"\n ...\n return abs(y_obs - y_hat)"}
{"task_id": "DSP/59", "completion": "def abs_loss(y_obs, y_hat):\n \"\"\"\n y_obs: an array of observed valued\n y_hat: an array of predicted values\n return an array corresponding to the loss for each prediction\n \"\"\"\n ...\n return abs(y_obs - y_hat)"}
{"task_id": "DSP/60", "completion": "def linear_model(x, theta):\n \"\"\"\n Returns the estimate of y given x and theta\n\n Keyword arguments:\n x -- the vector of values x\n theta -- the scalar theta\n \"\"\"\n y_hat = x * theta\n return y_hat"}
{"task_id": "DSP/60", "completion": "def linear_model(x, theta):\n \"\"\"\n Returns the estimate of y given x and theta\n\n Keyword arguments:\n x -- the vector of values x\n theta -- the scalar theta\n \"\"\"\n y_hat = x * theta\n return y_hat"}
{"task_id": "DSP/61", "completion": "def l2_loss(y, y_hat):\n \"\"\"\n Returns the average l2 loss given y and y_hat\n\n Keyword arguments:\n y -- the vector of true values y\n y_hat -- the vector of predicted values y_hat\n \"\"\"\n return np.mean((y - y_hat) ** 2)"}
{"task_id": "DSP/61", "completion": "def l2_loss(y, y_hat):\n \"\"\"\n Returns the average l2 loss given y and y_hat\n\n Keyword arguments:\n y -- the vector of true values y\n y_hat -- the vector of predicted values y_hat\n \"\"\"\n return np.mean((y - y_hat) ** 2)"}
{"task_id": "DSP/62", "completion": "def visualize(x, y, thetas):\n \"\"\"\n Plots the average l2 loss for given x, y as a function of theta.\n Use the functions you wrote for linear_model and l2_loss.\n\n Keyword arguments:\n x -- the vector of values x\n y -- the vector of values y\n thetas -- the vector containing different estimates of theta\n \"\"\"\n avg_loss = [l2_loss(y, linear_model(theta, x)) for theta in thetas] # Calculate the loss here for each value of theta\n \n fig = plt.figure(figsize=(8,6))\n ax = plt.axes()\n plt.plot(thetas, avg_loss)\n ax.set(xlabel = r\"$\\theta$\", ylabel = r\"Average Loss\")\n \nthetas = np.linspace(-1, 5, 70)\nvisualize(x, y, thetas)\ntheta_star_guess = 1.5"}
{"task_id": "DSP/62", "completion": "def visualize(x, y, thetas):\n \"\"\"\n Plots the average l2 loss for given x, y as a function of theta.\n Use the functions you wrote for linear_model and l2_loss.\n\n Keyword arguments:\n x -- the vector of values x\n y -- the vector of values y\n thetas -- the vector containing different estimates of theta\n \"\"\"\n avg_loss = [l2_loss(y, linear_model(theta, x)) for theta in thetas] # Calculate the loss here for each value of theta\n \n fig = plt.figure(figsize=(8,6))\n ax = plt.axes()\n plt.plot(thetas, avg_loss)\n ax.set(xlabel = r\"$\\theta$\", ylabel = r\"Average Loss\")\n \nthetas = np.linspace(-1, 5, 70)\nvisualize(x, y, thetas)\ntheta_star_guess = 1.5"}
{"task_id": "DSP/63", "completion": "def find_theta(x, y):\n \"\"\"\n Find optimal theta given x and y\n\n Keyword arguments:\n x -- the vector of values x\n y -- the vector of values y\n \"\"\"\n theta_opt = (x * y).sum() / (x ** 2).sum()\n return theta_opt"}
{"task_id": "DSP/63", "completion": "def find_theta(x, y):\n \"\"\"\n Find optimal theta given x and y\n\n Keyword arguments:\n x -- the vector of values x\n y -- the vector of values y\n \"\"\"\n theta_opt = (x * y).sum() / (x ** 2).sum()\n return theta_opt"}
{"task_id": "DSP/64", "completion": "def sin_model(x, theta_1, theta_2):\n \"\"\"\n Predict the estimate of y given x, theta_1, theta_2\n\n Keyword arguments:\n x -- the vector of values x\n theta_1 -- the scalar value theta_1\n theta_2 -- the scalar value theta_2\n \"\"\"\n y_hat = theta_1 * x + np.sin(theta_2 * x)\n return y_hat"}
{"task_id": "DSP/64", "completion": "def sin_model(x, theta_1, theta_2):\n \"\"\"\n Predict the estimate of y given x, theta_1, theta_2\n\n Keyword arguments:\n x -- the vector of values x\n theta_1 -- the scalar value theta_1\n theta_2 -- the scalar value theta_2\n \"\"\"\n y_hat = theta_1 * x + np.sin(theta_2 * x)\n return y_hat"}
{"task_id": "DSP/65", "completion": "def grad_desc(x, y, theta, num_iter=20, alpha=0.1):\n \"\"\"\n Run gradient descent update for a finite number of iterations and static learning rate\n\n Keyword arguments:\n x -- the vector of values x\n y -- the vector of values y\n theta -- the vector of values theta to use at first iteration\n num_iter -- the max number of iterations\n alpha -- the learning rate (also called the step size)\n \n Return:\n theta -- the optimal value of theta after num_iter of gradient descent\n theta_history -- the series of theta values over each iteration of gradient descent\n loss_history -- the series of loss values over each iteration of gradient descent\n \"\"\"\n theta_history = []\n loss_history = []\n \n for i in np.arange(num_iter):\n theta_history.append(theta)\n loss_history.append(l2_loss(y,sin_model(x, theta[0], theta[1]))) \n theta = theta - alpha * dt(x, y, theta)\n return theta, theta_history, loss_history"}
{"task_id": "DSP/65", "completion": "def grad_desc(x, y, theta, num_iter=20, alpha=0.1):\n \"\"\"\n Run gradient descent update for a finite number of iterations and static learning rate\n\n Keyword arguments:\n x -- the vector of values x\n y -- the vector of values y\n theta -- the vector of values theta to use at first iteration\n num_iter -- the max number of iterations\n alpha -- the learning rate (also called the step size)\n \n Return:\n theta -- the optimal value of theta after num_iter of gradient descent\n theta_history -- the series of theta values over each iteration of gradient descent\n loss_history -- the series of loss values over each iteration of gradient descent\n \"\"\"\n theta_history = []\n loss_history = []\n \n for i in np.arange(num_iter):\n theta_history.append(theta)\n loss_history.append(l2_loss(y,sin_model(x, theta[0], theta[1]))) \n theta = theta - alpha * dt(x, y, theta)\n return theta, theta_history, loss_history"}
{"task_id": "DSP/66", "completion": "def grad_desc_decay(x, y, theta, num_iter=20, alpha=0.1):\n \"\"\"\n Run gradient descent update for a finite number of iterations and decaying learning rate\n\n Keyword arguments:\n x -- the vector of values x\n y -- the vector of values y\n theta -- the vector of values theta\n num_iter -- the max number of iterations\n alpha -- the learning rate\n \n Return:\n theta -- the optimal value of theta after num_iter of gradient descent\n theta_history -- the series of theta values over each iteration of gradient descent\n loss_history -- the series of loss values over each iteration of gradient descent\n \"\"\"\n theta_history = []\n loss_history = []\n \n for i in np.arange(num_iter):\n theta_history.append(theta)\n loss_history.append(l2_loss(y,sin_model(x, theta[0], theta[1])))\n theta = theta - alpha * dt(x, y, theta)\n alpha = alpha / (i + 1)\n return theta, theta_history, loss_history"}
{"task_id": "DSP/66", "completion": "def grad_desc_decay(x, y, theta, num_iter=20, alpha=0.1):\n \"\"\"\n Run gradient descent update for a finite number of iterations and decaying learning rate\n\n Keyword arguments:\n x -- the vector of values x\n y -- the vector of values y\n theta -- the vector of values theta\n num_iter -- the max number of iterations\n alpha -- the learning rate\n \n Return:\n theta -- the optimal value of theta after num_iter of gradient descent\n theta_history -- the series of theta values over each iteration of gradient descent\n loss_history -- the series of loss values over each iteration of gradient descent\n \"\"\"\n theta_history = []\n loss_history = []\n \n for i in np.arange(num_iter):\n theta_history.append(theta)\n loss_history.append(l2_loss(y,sin_model(x, theta[0], theta[1])))\n theta = theta - alpha * dt(x, y, theta)\n alpha = alpha / (i + 1)\n return theta, theta_history, loss_history"}
{"task_id": "DSP/67", "completion": "colours = []\n\n##BEGIN SOLUTION\ncolours = [\"red\", \"orange\", \"yellow\", \"green\", \"blue\", \"indigo\", \"violet\"]\n#END SOLUTION"}
{"task_id": "DSP/67", "completion": "colours = []\n\n##BEGIN SOLUTION\ncolours = [\"red\", \"orange\", \"yellow\", \"green\", \"blue\", \"indigo\", \"violet\"]\n#END SOLUTION"}
{"task_id": "DSP/68", "completion": "def get_string(x,y):\n return str(x) + str(y)\n raise NotImplementedError()"}
{"task_id": "DSP/68", "completion": "def get_string(x,y):\n return str(x) + str(y)\n raise NotImplementedError()"}
{"task_id": "DSP/69", "completion": "def ypolynomial(x,p):\n if x > 0:\n x = x**p\n y = 4 + 5*x\n else: \n y = 0\n return y\n raise NotImplementedError()"}
{"task_id": "DSP/69", "completion": "def ypolynomial(x,p):\n if x > 0:\n x = x**p\n y = 4 + 5*x\n else: \n y = 0\n return y\n raise NotImplementedError()"}
{"task_id": "DSP/70", "completion": "def divisibles(N, p):\n result = []\n if N < 0:\n N=20\n else:\n pass\n \n i = 0\n while i <= N:\n if i%p == 0:\n result.append(i)\n else:\n pass\n i+=1\n return result\n raise NotImplementedError()"}
{"task_id": "DSP/70", "completion": "def divisibles(N, p):\n result = []\n if N < 0:\n N=20\n else:\n pass\n \n i = 0\n while i <= N:\n if i%p == 0:\n result.append(i)\n else:\n pass\n i+=1\n return result\n raise NotImplementedError()"}
{"task_id": "DSP/71", "completion": "def divisibles2(s, N, p):\n result = []\n if N < 0:\n N=20\n else:\n pass\n \n i = s\n while i <= N:\n if i%p == 0:\n result.append(i)\n else:\n pass\n i+=1\n return result\n raise NotImplementedError()"}
{"task_id": "DSP/71", "completion": "def divisibles2(s, N, p):\n result = []\n if N < 0:\n N=20\n else:\n pass\n \n i = s\n while i <= N:\n if i%p == 0:\n result.append(i)\n else:\n pass\n i+=1\n return result\n raise NotImplementedError()"}
{"task_id": "DSP/72", "completion": "def divisibo(N):\n result = []\n divs = [5, 7, 11]\n start = divs[2]\n \n while(len(result) < N):\n if start%11 == 0:\n if start%7 == 0:\n if start%5 == 0:\n result.append(start)\n start+=1\n return result\n raise NotImplementedError()"}
{"task_id": "DSP/72", "completion": "def divisibo(N):\n result = []\n divs = [5, 7, 11]\n start = divs[2]\n \n while(len(result) < N):\n if start%11 == 0:\n if start%7 == 0:\n if start%5 == 0:\n result.append(start)\n start+=1\n return result\n raise NotImplementedError()"}
{"task_id": "DSP/73", "completion": "def primes_first(N):\n result = [2]\n i = 2\n while(len(result) < N):\n if(i%2 != 0):\n result.append(i)\n i+=1\n return result\n raise NotImplementedError()"}
{"task_id": "DSP/73", "completion": "def primes_first(N):\n result = [2]\n i = 2\n while(len(result) < N):\n if(i%2 != 0):\n result.append(i)\n i+=1\n return result\n raise NotImplementedError()"}
{"task_id": "DSP/74", "completion": "def flatten_list(superlist):\n # Flatten array\n sort = []\n i = 0\n while i < len(superlist):\n z = 0\n while(z < len(superlist[i])):\n sort.append(superlist[i][z])\n z+=1\n i+=1\n # Bubble sort\n for p in range(len(sort)-1,0,-1):\n for x in range(p):\n if sort[x]>sort[x+1]:\n tmp = sort[x]\n sort[x] = sort[x+1]\n sort[x+1] = tmp\n return sort\n raise NotImplementedError()"}
{"task_id": "DSP/74", "completion": "def flatten_list(superlist):\n # Flatten array\n sort = []\n i = 0\n while i < len(superlist):\n z = 0\n while(z < len(superlist[i])):\n sort.append(superlist[i][z])\n z+=1\n i+=1\n # Bubble sort\n for p in range(len(sort)-1,0,-1):\n for x in range(p):\n if sort[x]>sort[x+1]:\n tmp = sort[x]\n sort[x] = sort[x+1]\n sort[x+1] = tmp\n return sort\n raise NotImplementedError()"}
{"task_id": "DSP/75", "completion": "def longest_word(text):\n words = text.split()\n largest = 0\n for word in words:\n current_len = len(word)\n if (current_len > largest):\n final_word = word\n largest = current_len\n else:\n largest = largest\n return final_word\n raise NotImplementedError()"}
{"task_id": "DSP/75", "completion": "def longest_word(text):\n words = text.split()\n largest = 0\n for word in words:\n current_len = len(word)\n if (current_len > largest):\n final_word = word\n largest = current_len\n else:\n largest = largest\n return final_word\n raise NotImplementedError()"}
{"task_id": "DSP/76", "completion": "def dictionarize(alist):\n diction = {}\n for x in alist:\n i = alist.count(x)\n if i > 0:\n diction[x] = i\n return diction\n raise NotImplementedError()"}
{"task_id": "DSP/76", "completion": "def dictionarize(alist):\n diction = {}\n for x in alist:\n i = alist.count(x)\n if i > 0:\n diction[x] = i\n return diction\n raise NotImplementedError()"}
{"task_id": "DSP/77", "completion": "var_a = ['a','b','c','d','e','f','g','h','i','j']\nvar_b = (1,2,3,4,5,6,7,8,9,10)"}
{"task_id": "DSP/77", "completion": "var_a = ['a','b','c','d','e','f','g','h','i','j']\nvar_b = (1,2,3,4,5,6,7,8,9,10)"}
{"task_id": "DSP/78", "completion": "dictionary = dict(zip(var_a,var_b))"}
{"task_id": "DSP/78", "completion": "dictionary = dict(zip(var_a,var_b))"}
{"task_id": "DSP/79", "completion": "lst = [1, 2, 3, 4, 5, 6]\ninds = []\n\n# Loop through the provided list 'lst'. For each element, check if it is an even number.\n# If the element is an even number, add the INDEX of that element to the list 'inds'.\n# Note that you are adding the index to 'inds', not the element itself.\n# Hint: to check if a number is even, you can use the modulo '%' operator.\n# Hint: to loop through an iterable, keeping track of the index, you can use the 'enumerate' function.\n\nfor index, item in enumerate(lst,0):\n if index%2==0:\n inds.append(item)"}
{"task_id": "DSP/79", "completion": "lst = [1, 2, 3, 4, 5, 6]\ninds = []\n\n# Loop through the provided list 'lst'. For each element, check if it is an even number.\n# If the element is an even number, add the INDEX of that element to the list 'inds'.\n# Note that you are adding the index to 'inds', not the element itself.\n# Hint: to check if a number is even, you can use the modulo '%' operator.\n# Hint: to loop through an iterable, keeping track of the index, you can use the 'enumerate' function.\n\nfor index, item in enumerate(lst,0):\n if index%2==0:\n inds.append(item)"}
{"task_id": "DSP/80", "completion": "def add2(input1,input2):\n return input1+input2"}
{"task_id": "DSP/80", "completion": "def add2(input1,input2):\n return input1+input2"}
{"task_id": "DSP/81", "completion": "other_dictionary = dict()\n\n# We will now fill 'other_dictionary', from data.\n# Loop through the key-value pairs in 'dictionary'.\n# For each key-value pair, if the value is odd, use the 'add2' to add 1 to the value.\n# Add the key and incremented value to 'other_dictionary'.\n# Otherwise, add the key-value pair to 'other_dictionary' as is.\n# Note: to loop through key-value pairs in a dictionary, check out the '.items' method.\nfor k,v in dictionary.items():\n if v%2==1:\n other_dictionary[k] = add2(v,1)\n else:\n other_dictionary[k] = v"}
{"task_id": "DSP/81", "completion": "other_dictionary = dict()\n\n# We will now fill 'other_dictionary', from data.\n# Loop through the key-value pairs in 'dictionary'.\n# For each key-value pair, if the value is odd, use the 'add2' to add 1 to the value.\n# Add the key and incremented value to 'other_dictionary'.\n# Otherwise, add the key-value pair to 'other_dictionary' as is.\n# Note: to loop through key-value pairs in a dictionary, check out the '.items' method.\nfor k,v in dictionary.items():\n if v%2==1:\n other_dictionary[k] = add2(v,1)\n else:\n other_dictionary[k] = v"}
{"task_id": "DSP/82", "completion": "import numpy as np\nimport scipy as sp\nimport pandas as pd\nimport matplotlib as plt\nimport sklearn as skl"}
{"task_id": "DSP/82", "completion": "import numpy as np\nimport scipy as sp\nimport pandas as pd\nimport matplotlib as plt\nimport sklearn as skl"}
{"task_id": "DSP/83", "completion": "var_a = 'a b c d e f g h i j'.split(' ')\nvar_b = tuple(range(1, 11))\n### END SOLUTION"}
{"task_id": "DSP/83", "completion": "var_a = 'a b c d e f g h i j'.split(' ')\nvar_b = tuple(range(1, 11))\n### END SOLUTION"}
{"task_id": "DSP/84", "completion": "dictionary = dict()\nfor a, b in zip(var_a, var_b):\n dictionary[a] = b\n# The following is also perfectly valid:\n# dictionary = dict(zip(var_a, var_b))\n### END SOLUTION"}
{"task_id": "DSP/84", "completion": "dictionary = dict()\nfor a, b in zip(var_a, var_b):\n dictionary[a] = b\n# The following is also perfectly valid:\n# dictionary = dict(zip(var_a, var_b))\n### END SOLUTION"}
{"task_id": "DSP/85", "completion": "lst = [1, 2, 3, 4, 5, 6]\ninds = []\n\n# Loop through the provided list 'lst'. For each element, check if it is an even number.\n# If the element is an even number, add the INDEX of that element to the list 'inds'.\n# Note that you are adding the index to 'inds', not the element itself.\n# Hint: to check if a number is even, you can use the modulo '%' operator.\n# Hint: to loop through an iterable, keeping track of the index, you can use the 'enumerate' function.\n\n### BEGIN SOLUTION\nfor ind, it in enumerate(lst):\n if it % 2 == 0:\n inds.append(ind)\n### END SOLUTION"}
{"task_id": "DSP/85", "completion": "lst = [1, 2, 3, 4, 5, 6]\ninds = []\n\n# Loop through the provided list 'lst'. For each element, check if it is an even number.\n# If the element is an even number, add the INDEX of that element to the list 'inds'.\n# Note that you are adding the index to 'inds', not the element itself.\n# Hint: to check if a number is even, you can use the modulo '%' operator.\n# Hint: to loop through an iterable, keeping track of the index, you can use the 'enumerate' function.\n\n### BEGIN SOLUTION\nfor ind, it in enumerate(lst):\n if it % 2 == 0:\n inds.append(ind)\n### END SOLUTION"}
{"task_id": "DSP/86", "completion": "def add2(a, b):\n return a + b\n### END SOLUTION"}
{"task_id": "DSP/86", "completion": "def add2(a, b):\n return a + b\n### END SOLUTION"}
{"task_id": "DSP/87", "completion": "other_dictionary = dict()\n\n# We will now fill 'other_dictionary', from data.\n# Loop through the key-value pairs in 'dictionary'.\n# For each key-value pair, if the value is odd, use the 'add2' to add 1 to the value.\n# Add the key and incremented value to 'other_dictionary'.\n# Otherwise, add the key-value pair to 'other_dictionary' as is.\n# Note: to loop through key-value pairs in a dictionary, check out the '.items' method.\n\n### BEGIN SOLUTION\nfor ke, va in dictionary.items():\n if va % 2 != 0:\n other_dictionary[ke] = add2(va, 1)\n else:\n other_dictionary[ke] = va\n### END SOLUTION"}
{"task_id": "DSP/87", "completion": "other_dictionary = dict()\n\n# We will now fill 'other_dictionary', from data.\n# Loop through the key-value pairs in 'dictionary'.\n# For each key-value pair, if the value is odd, use the 'add2' to add 1 to the value.\n# Add the key and incremented value to 'other_dictionary'.\n# Otherwise, add the key-value pair to 'other_dictionary' as is.\n# Note: to loop through key-value pairs in a dictionary, check out the '.items' method.\n\n### BEGIN SOLUTION\nfor ke, va in dictionary.items():\n if va % 2 != 0:\n other_dictionary[ke] = add2(va, 1)\n else:\n other_dictionary[ke] = va\n### END SOLUTION"}
{"task_id": "DSP/88", "completion": "import numpy as np\nimport scipy as sp\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport sklearn as skl\n### END SOLUTION"}
{"task_id": "DSP/88", "completion": "import numpy as np\nimport scipy as sp\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport sklearn as skl\n### END SOLUTION"}
{"task_id": "DSP/89", "completion": "a = 1\n### END SOLUTION"}
{"task_id": "DSP/89", "completion": "a = 1\n### END SOLUTION"}
{"task_id": "DSP/90", "completion": "b = '2'\n### END SOLUTION"}
{"task_id": "DSP/90", "completion": "b = '2'\n### END SOLUTION"}
{"task_id": "DSP/91", "completion": "ds = True\n### END SOLUTION"}
{"task_id": "DSP/91", "completion": "ds = True\n### END SOLUTION"}
{"task_id": "DSP/92", "completion": "array = np.array(range(5))\n### END SOLUTION"}
{"task_id": "DSP/92", "completion": "array = np.array(range(5))\n### END SOLUTION"}
{"task_id": "DSP/93", "completion": "a = 1\n### END SOLUTION"}
{"task_id": "DSP/93", "completion": "a = 1\n### END SOLUTION"}
{"task_id": "DSP/94", "completion": "b = '2'\n### END SOLUTION"}
{"task_id": "DSP/94", "completion": "b = '2'\n### END SOLUTION"}
{"task_id": "DSP/95", "completion": "ds = True\n### END SOLUTION"}
{"task_id": "DSP/95", "completion": "ds = True\n### END SOLUTION"}
{"task_id": "DSP/96", "completion": "array = np.array(range(5))\n### END SOLUTION"}
{"task_id": "DSP/96", "completion": "array = np.array(range(5))\n### END SOLUTION"}
{"task_id": "DSP/97", "completion": "var_a = ['a','b','c','d','e','f','g','h','i','j']\nvar_b = (1,2,3,4,5,6,7,8,9,10)"}
{"task_id": "DSP/97", "completion": "var_a = ['a','b','c','d','e','f','g','h','i','j']\nvar_b = (1,2,3,4,5,6,7,8,9,10)"}
{"task_id": "DSP/98", "completion": "dictionary = dict(zip(var_a,var_b))"}
{"task_id": "DSP/98", "completion": "dictionary = dict(zip(var_a,var_b))"}
{"task_id": "DSP/99", "completion": "lst = [1, 2, 3, 4, 5, 6]\ninds = []\n\n# Loop through the provided list 'lst'. For each element, check if it is an even number.\n# If the element is an even number, add the INDEX of that element to the list 'inds'.\n# Note that you are adding the index to 'inds', not the element itself.\n# Hint: to check if a number is even, you can use the modulo '%' operator.\n# Hint: to loop through an iterable, keeping track of the index, you can use the 'enumerate' function.\n\nfor index, item in enumerate(lst,0):\n if index%2==0:\n inds.append(item)"}
{"task_id": "DSP/99", "completion": "lst = [1, 2, 3, 4, 5, 6]\ninds = []\n\n# Loop through the provided list 'lst'. For each element, check if it is an even number.\n# If the element is an even number, add the INDEX of that element to the list 'inds'.\n# Note that you are adding the index to 'inds', not the element itself.\n# Hint: to check if a number is even, you can use the modulo '%' operator.\n# Hint: to loop through an iterable, keeping track of the index, you can use the 'enumerate' function.\n\nfor index, item in enumerate(lst,0):\n if index%2==0:\n inds.append(item)"}
{"task_id": "DSP/100", "completion": "def add2(input1,input2):\n return input1+input2"}
{"task_id": "DSP/100", "completion": "def add2(input1,input2):\n return input1+input2"}
{"task_id": "DSP/101", "completion": "other_dictionary = dict()\n\n# We will now fill 'other_dictionary', from data.\n# Loop through the key-value pairs in 'dictionary'.\n# For each key-value pair, if the value is odd, use the 'add2' to add 1 to the value.\n# Add the key and incremented value to 'other_dictionary'.\n# Otherwise, add the key-value pair to 'other_dictionary' as is.\n# Note: to loop through key-value pairs in a dictionary, check out the '.items' method.\nfor k,v in dictionary.items():\n if v%2==1:\n other_dictionary[k] = add2(v,1)\n else:\n other_dictionary[k] = v"}
{"task_id": "DSP/101", "completion": "other_dictionary = dict()\n\n# We will now fill 'other_dictionary', from data.\n# Loop through the key-value pairs in 'dictionary'.\n# For each key-value pair, if the value is odd, use the 'add2' to add 1 to the value.\n# Add the key and incremented value to 'other_dictionary'.\n# Otherwise, add the key-value pair to 'other_dictionary' as is.\n# Note: to loop through key-value pairs in a dictionary, check out the '.items' method.\nfor k,v in dictionary.items():\n if v%2==1:\n other_dictionary[k] = add2(v,1)\n else:\n other_dictionary[k] = v"}
{"task_id": "DSP/102", "completion": "import numpy as np\nimport scipy as sp\nimport pandas as pd\nimport matplotlib as plt\nimport sklearn as skl"}
{"task_id": "DSP/102", "completion": "import numpy as np\nimport scipy as sp\nimport pandas as pd\nimport matplotlib as plt\nimport sklearn as skl"}
{"task_id": "DSP/103", "completion": "var_a = 'a b c d e f g h i j'.split(' ')\nvar_b = tuple(range(1, 11))\n### END SOLUTION"}
{"task_id": "DSP/103", "completion": "var_a = 'a b c d e f g h i j'.split(' ')\nvar_b = tuple(range(1, 11))\n### END SOLUTION"}
{"task_id": "DSP/104", "completion": "dictionary = dict()\nfor a, b in zip(var_a, var_b):\n dictionary[a] = b\n# The following is also perfectly valid:\n# dictionary = dict(zip(var_a, var_b))\n### END SOLUTION"}
{"task_id": "DSP/104", "completion": "dictionary = dict()\nfor a, b in zip(var_a, var_b):\n dictionary[a] = b\n# The following is also perfectly valid:\n# dictionary = dict(zip(var_a, var_b))\n### END SOLUTION"}
{"task_id": "DSP/105", "completion": "lst = [1, 2, 3, 4, 5, 6]\ninds = []\n\n# Loop through the provided list 'lst'. For each element, check if it is an even number.\n# If the element is an even number, add the INDEX of that element to the list 'inds'.\n# Note that you are adding the index to 'inds', not the element itself.\n# Hint: to check if a number is even, you can use the modulo '%' operator.\n# Hint: to loop through an iterable, keeping track of the index, you can use the 'enumerate' function.\n\n### BEGIN SOLUTION\nfor ind, it in enumerate(lst):\n if it % 2 == 0:\n inds.append(ind)\n### END SOLUTION"}
{"task_id": "DSP/105", "completion": "lst = [1, 2, 3, 4, 5, 6]\ninds = []\n\n# Loop through the provided list 'lst'. For each element, check if it is an even number.\n# If the element is an even number, add the INDEX of that element to the list 'inds'.\n# Note that you are adding the index to 'inds', not the element itself.\n# Hint: to check if a number is even, you can use the modulo '%' operator.\n# Hint: to loop through an iterable, keeping track of the index, you can use the 'enumerate' function.\n\n### BEGIN SOLUTION\nfor ind, it in enumerate(lst):\n if it % 2 == 0:\n inds.append(ind)\n### END SOLUTION"}
{"task_id": "DSP/106", "completion": "def add2(a, b):\n return a + b\n### END SOLUTION"}
{"task_id": "DSP/106", "completion": "def add2(a, b):\n return a + b\n### END SOLUTION"}
{"task_id": "DSP/107", "completion": "other_dictionary = dict()\n\n# We will now fill 'other_dictionary', from data.\n# Loop through the key-value pairs in 'dictionary'.\n# For each key-value pair, if the value is odd, use the 'add2' to add 1 to the value.\n# Add the key and incremented value to 'other_dictionary'.\n# Otherwise, add the key-value pair to 'other_dictionary' as is.\n# Note: to loop through key-value pairs in a dictionary, check out the '.items' method.\n\n### BEGIN SOLUTION\nfor ke, va in dictionary.items():\n if va % 2 != 0:\n other_dictionary[ke] = add2(va, 1)\n else:\n other_dictionary[ke] = va\n### END SOLUTION"}
{"task_id": "DSP/107", "completion": "other_dictionary = dict()\n\n# We will now fill 'other_dictionary', from data.\n# Loop through the key-value pairs in 'dictionary'.\n# For each key-value pair, if the value is odd, use the 'add2' to add 1 to the value.\n# Add the key and incremented value to 'other_dictionary'.\n# Otherwise, add the key-value pair to 'other_dictionary' as is.\n# Note: to loop through key-value pairs in a dictionary, check out the '.items' method.\n\n### BEGIN SOLUTION\nfor ke, va in dictionary.items():\n if va % 2 != 0:\n other_dictionary[ke] = add2(va, 1)\n else:\n other_dictionary[ke] = va\n### END SOLUTION"}
{"task_id": "DSP/108", "completion": "import numpy as np\nimport scipy as sp\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport sklearn as skl\n### END SOLUTION"}
{"task_id": "DSP/108", "completion": "import numpy as np\nimport scipy as sp\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport sklearn as skl\n### END SOLUTION"}
{"task_id": "DSP/109", "completion": "a = 1\n### END SOLUTION"}
{"task_id": "DSP/109", "completion": "a = 1\n### END SOLUTION"}
{"task_id": "DSP/110", "completion": "b = '2'\n### END SOLUTION"}
{"task_id": "DSP/110", "completion": "b = '2'\n### END SOLUTION"}
{"task_id": "DSP/111", "completion": "ds = True\n### END SOLUTION"}
{"task_id": "DSP/111", "completion": "ds = True\n### END SOLUTION"}
{"task_id": "DSP/112", "completion": "array = np.array(range(5))\n### END SOLUTION"}
{"task_id": "DSP/112", "completion": "array = np.array(range(5))\n### END SOLUTION"}
{"task_id": "DSP/113", "completion": "var_a = 'a b c d e f g h i j'.split(' ')\nvar_b = tuple(range(1, 11))\n### END SOLUTION"}
{"task_id": "DSP/113", "completion": "var_a = 'a b c d e f g h i j'.split(' ')\nvar_b = tuple(range(1, 11))\n### END SOLUTION"}
{"task_id": "DSP/114", "completion": "dictionary = dict()\nfor a, b in zip(var_a, var_b):\n dictionary[a] = b\n# The following is also perfectly valid:\n# dictionary = dict(zip(var_a, var_b))\n### END SOLUTION"}
{"task_id": "DSP/114", "completion": "dictionary = dict()\nfor a, b in zip(var_a, var_b):\n dictionary[a] = b\n# The following is also perfectly valid:\n# dictionary = dict(zip(var_a, var_b))\n### END SOLUTION"}
{"task_id": "DSP/115", "completion": "lst = [1, 2, 3, 4, 5, 6]\ninds = []\n\n# Loop through the provided list 'lst'. For each element, check if it is an even number.\n# If the element is an even number, add the INDEX of that element to the list 'inds'.\n# Note that you are adding the index to 'inds', not the element itself.\n# Hint: to check if a number is even, you can use the modulo '%' operator.\n# Hint: to loop through an iterable, keeping track of the index, you can use the 'enumerate' function.\n\n### BEGIN SOLUTION\nfor ind, it in enumerate(lst):\n if it % 2 == 0:\n inds.append(ind)\n### END SOLUTION"}
{"task_id": "DSP/115", "completion": "lst = [1, 2, 3, 4, 5, 6]\ninds = []\n\n# Loop through the provided list 'lst'. For each element, check if it is an even number.\n# If the element is an even number, add the INDEX of that element to the list 'inds'.\n# Note that you are adding the index to 'inds', not the element itself.\n# Hint: to check if a number is even, you can use the modulo '%' operator.\n# Hint: to loop through an iterable, keeping track of the index, you can use the 'enumerate' function.\n\n### BEGIN SOLUTION\nfor ind, it in enumerate(lst):\n if it % 2 == 0:\n inds.append(ind)\n### END SOLUTION"}
{"task_id": "DSP/116", "completion": "def add2(a, b):\n return a + b\n### END SOLUTION"}
{"task_id": "DSP/116", "completion": "def add2(a, b):\n return a + b\n### END SOLUTION"}
{"task_id": "DSP/117", "completion": "other_dictionary = dict()\n\n# We will now fill 'other_dictionary', from data.\n# Loop through the key-value pairs in 'dictionary'.\n# For each key-value pair, if the value is odd, use the 'add2' to add 1 to the value.\n# Add the key and incremented value to 'other_dictionary'.\n# Otherwise, add the key-value pair to 'other_dictionary' as is.\n# Note: to loop through key-value pairs in a dictionary, check out the '.items' method.\n\n### BEGIN SOLUTION\nfor ke, va in dictionary.items():\n if va % 2 != 0:\n other_dictionary[ke] = add2(va, 1)\n else:\n other_dictionary[ke] = va\n### END SOLUTION"}
{"task_id": "DSP/117", "completion": "other_dictionary = dict()\n\n# We will now fill 'other_dictionary', from data.\n# Loop through the key-value pairs in 'dictionary'.\n# For each key-value pair, if the value is odd, use the 'add2' to add 1 to the value.\n# Add the key and incremented value to 'other_dictionary'.\n# Otherwise, add the key-value pair to 'other_dictionary' as is.\n# Note: to loop through key-value pairs in a dictionary, check out the '.items' method.\n\n### BEGIN SOLUTION\nfor ke, va in dictionary.items():\n if va % 2 != 0:\n other_dictionary[ke] = add2(va, 1)\n else:\n other_dictionary[ke] = va\n### END SOLUTION"}
{"task_id": "DSP/118", "completion": "import numpy as np\nimport scipy as sp\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport sklearn as skl\n### END SOLUTION"}
{"task_id": "DSP/118", "completion": "import numpy as np\nimport scipy as sp\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport sklearn as skl\n### END SOLUTION"}
{"task_id": "DSP/119", "completion": "var_a = ['a','b','c','d','e','f','g','h','i','j']\nvar_b = (1,2,3,4,5,6,7,8,9,10)"}
{"task_id": "DSP/119", "completion": "var_a = ['a','b','c','d','e','f','g','h','i','j']\nvar_b = (1,2,3,4,5,6,7,8,9,10)"}
{"task_id": "DSP/120", "completion": "dictionary = dict(zip(var_a,var_b))"}
{"task_id": "DSP/120", "completion": "dictionary = dict(zip(var_a,var_b))"}
{"task_id": "DSP/121", "completion": "lst = [1, 2, 3, 4, 5, 6]\ninds = []\n\n# Loop through the provided list 'lst'. For each element, check if it is an even number.\n# If the element is an even number, add the INDEX of that element to the list 'inds'.\n# Note that you are adding the index to 'inds', not the element itself.\n# Hint: to check if a number is even, you can use the modulo '%' operator.\n# Hint: to loop through an iterable, keeping track of the index, you can use the 'enumerate' function.\n\nfor index, item in enumerate(lst,0):\n if index%2==0:\n inds.append(item)"}
{"task_id": "DSP/121", "completion": "lst = [1, 2, 3, 4, 5, 6]\ninds = []\n\n# Loop through the provided list 'lst'. For each element, check if it is an even number.\n# If the element is an even number, add the INDEX of that element to the list 'inds'.\n# Note that you are adding the index to 'inds', not the element itself.\n# Hint: to check if a number is even, you can use the modulo '%' operator.\n# Hint: to loop through an iterable, keeping track of the index, you can use the 'enumerate' function.\n\nfor index, item in enumerate(lst,0):\n if index%2==0:\n inds.append(item)"}
{"task_id": "DSP/122", "completion": "def add2(input1,input2):\n return input1+input2"}
{"task_id": "DSP/122", "completion": "def add2(input1,input2):\n return input1+input2"}
{"task_id": "DSP/123", "completion": "other_dictionary = dict()\n\n# We will now fill 'other_dictionary', from data.\n# Loop through the key-value pairs in 'dictionary'.\n# For each key-value pair, if the value is odd, use the 'add2' to add 1 to the value.\n# Add the key and incremented value to 'other_dictionary'.\n# Otherwise, add the key-value pair to 'other_dictionary' as is.\n# Note: to loop through key-value pairs in a dictionary, check out the '.items' method.\nfor k,v in dictionary.items():\n if v%2==1:\n other_dictionary[k] = add2(v,1)\n else:\n other_dictionary[k] = v"}
{"task_id": "DSP/123", "completion": "other_dictionary = dict()\n\n# We will now fill 'other_dictionary', from data.\n# Loop through the key-value pairs in 'dictionary'.\n# For each key-value pair, if the value is odd, use the 'add2' to add 1 to the value.\n# Add the key and incremented value to 'other_dictionary'.\n# Otherwise, add the key-value pair to 'other_dictionary' as is.\n# Note: to loop through key-value pairs in a dictionary, check out the '.items' method.\nfor k,v in dictionary.items():\n if v%2==1:\n other_dictionary[k] = add2(v,1)\n else:\n other_dictionary[k] = v"}
{"task_id": "DSP/124", "completion": "import numpy as np\nimport scipy as sp\nimport pandas as pd\nimport matplotlib as plt\nimport sklearn as skl"}
{"task_id": "DSP/124", "completion": "import numpy as np\nimport scipy as sp\nimport pandas as pd\nimport matplotlib as plt\nimport sklearn as skl"}
{"task_id": "DSP/125", "completion": "def separate_by_class(X, y):\n '''\n Separate the training set (\"X\") by class value (\"y\")\n so that we can calculate statistics for each class.\n \n Parameters\n ----------\n X: A 2d numpy array\n y: A 1d numpy array\n Returns\n -------\n A dictionary of 2d numpy arrays\n '''\n ##################\n # YOUR CODE HERE\n separated = {}\n labels = np.unique(y) # find all unique labels\n for item in labels:\n separated[item] = X[np.where(y == item)] # use np.where to find index of all corresponding items in X\n ##################\n\n return separated"}
{"task_id": "DSP/125", "completion": "def separate_by_class(X, y):\n '''\n Separate the training set (\"X\") by class value (\"y\")\n so that we can calculate statistics for each class.\n \n Parameters\n ----------\n X: A 2d numpy array\n y: A 1d numpy array\n Returns\n -------\n A dictionary of 2d numpy arrays\n '''\n ##################\n # YOUR CODE HERE\n separated = {}\n labels = np.unique(y) # find all unique labels\n for item in labels:\n separated[item] = X[np.where(y == item)] # use np.where to find index of all corresponding items in X\n ##################\n\n return separated"}
{"task_id": "DSP/126", "completion": "def calculate_mean(array):\n '''\n Calculates the mean of each column, i.e. each attribute.\n \n Parameters\n ----------\n A 1d or 2d numpy array\n \n Returns\n -------\n A 1d or 2d numpy array\n '''\n ##################\n # YOUR CODE HERE\n mean = np.mean(array, axis=0)\n ##################\n return mean"}
{"task_id": "DSP/126", "completion": "def calculate_mean(array):\n '''\n Calculates the mean of each column, i.e. each attribute.\n \n Parameters\n ----------\n A 1d or 2d numpy array\n \n Returns\n -------\n A 1d or 2d numpy array\n '''\n ##################\n # YOUR CODE HERE\n mean = np.mean(array, axis=0)\n ##################\n return mean"}
{"task_id": "DSP/127", "completion": "def calculate_stdev(array):\n '''\n Calculates the standard deviation of each column, i.e. each attribute.\n\n Parameters\n ----------\n A 1d or 2d numpy array\n \n Returns\n -------\n A 1d or 2d numpy array\n '''\n ##################\n # YOUR CODE HERE\n stdev = np.std(array, axis=0, ddof=1) # need to set the delta degree of freedom to be 1\n ##################\n\n return stdev"}
{"task_id": "DSP/127", "completion": "def calculate_stdev(array):\n '''\n Calculates the standard deviation of each column, i.e. each attribute.\n\n Parameters\n ----------\n A 1d or 2d numpy array\n \n Returns\n -------\n A 1d or 2d numpy array\n '''\n ##################\n # YOUR CODE HERE\n stdev = np.std(array, axis=0, ddof=1) # need to set the delta degree of freedom to be 1\n ##################\n\n return stdev"}
{"task_id": "DSP/128", "completion": "def summarize(X):\n '''\n For a given list of instances (for a class value),\n calculates the mean and the standard deviation for each attribute.\n \n Parameters\n ----------\n A 2d numpy array\n \n Returns\n -------\n A 2d numpy array\n '''\n ##################\n # YOUR CODE HERE\n mean = calculate_mean(X)\n std = calculate_stdev(X)\n summary = np.vstack((mean, std)).T # stack it, and then transpose\n ##################\n return summary"}
{"task_id": "DSP/128", "completion": "def summarize(X):\n '''\n For a given list of instances (for a class value),\n calculates the mean and the standard deviation for each attribute.\n \n Parameters\n ----------\n A 2d numpy array\n \n Returns\n -------\n A 2d numpy array\n '''\n ##################\n # YOUR CODE HERE\n mean = calculate_mean(X)\n std = calculate_stdev(X)\n summary = np.vstack((mean, std)).T # stack it, and then transpose\n ##################\n return summary"}
{"task_id": "DSP/129", "completion": "def summarize_by_class(X, y):\n '''\n Separates a training set into instances grouped by class.\n It then calculates the summaries for each attribute.\n \n Parameters\n ----------\n X: A 2d numpy array. Represents training attributes.\n y: A 1d numpy array. Represents class labels.\n Returns\n -------\n A dictionary of 2d numpy arrays\n '''\n ##################\n # YOUR CODE HERE\n summaries = {}\n X_separated = separate_by_class(X, y)\n for key in X_separated:\n summaries[key] = summarize(X_separated[key])\n ##################\n\n return summaries"}
{"task_id": "DSP/129", "completion": "def summarize_by_class(X, y):\n '''\n Separates a training set into instances grouped by class.\n It then calculates the summaries for each attribute.\n \n Parameters\n ----------\n X: A 2d numpy array. Represents training attributes.\n y: A 1d numpy array. Represents class labels.\n Returns\n -------\n A dictionary of 2d numpy arrays\n '''\n ##################\n # YOUR CODE HERE\n summaries = {}\n X_separated = separate_by_class(X, y)\n for key in X_separated:\n summaries[key] = summarize(X_separated[key])\n ##################\n\n return summaries"}
{"task_id": "DSP/130", "completion": "def calculate_log_probability(x, mean, stdev):\n '''\n Calculates log of Gaussian function to estimate\n the log probability of a given attribute value.\n \n Parameters\n ----------\n x: A float or 1d numpy array\n mean: A float or 1d numpy array\n stdev: A float or 1d numpy array\n \n Returns\n -------\n A float or 1d numpy array\n '''\n\n ##################\n # YOUR CODE HERE\n from scipy.stats import norm\n \n temp = np.vstack([x, mean, stdev]).T # stack vertically and transpose, so that each row contains a set of x, mean, stdev\n log_probability = list(map(lambda x: norm.logpdf(*x), temp)) # map logpdf function to the list\n \n ##################\n\n return log_probability"}
{"task_id": "DSP/130", "completion": "def calculate_log_probability(x, mean, stdev):\n '''\n Calculates log of Gaussian function to estimate\n the log probability of a given attribute value.\n \n Parameters\n ----------\n x: A float or 1d numpy array\n mean: A float or 1d numpy array\n stdev: A float or 1d numpy array\n \n Returns\n -------\n A float or 1d numpy array\n '''\n\n ##################\n # YOUR CODE HERE\n from scipy.stats import norm\n \n temp = np.vstack([x, mean, stdev]).T # stack vertically and transpose, so that each row contains a set of x, mean, stdev\n log_probability = list(map(lambda x: norm.logpdf(*x), temp)) # map logpdf function to the list\n \n ##################\n\n return log_probability"}
{"task_id": "DSP/131", "completion": "def calculate_class_log_probabilities(summaries, input_array):\n '''\n Combines the probabilities of all of the attribute values for a data instance\n and comes up with a probability of the entire data instance belonging to the class.\n\n Parameters\n ----------\n summaries: A dictionary of 2d numpy arrays\n input_array: A 1d numpy array\n \n Returns\n -------\n A dictionary of log probabilities\n '''\n\n ##################\n # YOUR CODE HERE \n log_probabilities = {}\n for key in summaries:\n for summary_item in summaries[key]:\n log_probabilities[key] = calculate_log_probability(input_array, summary_item[0], summary_item[1])\n ##################\n\n return log_probabilities"}
{"task_id": "DSP/131", "completion": "def calculate_class_log_probabilities(summaries, input_array):\n '''\n Combines the probabilities of all of the attribute values for a data instance\n and comes up with a probability of the entire data instance belonging to the class.\n\n Parameters\n ----------\n summaries: A dictionary of 2d numpy arrays\n input_array: A 1d numpy array\n \n Returns\n -------\n A dictionary of log probabilities\n '''\n\n ##################\n # YOUR CODE HERE \n log_probabilities = {}\n for key in summaries:\n for summary_item in summaries[key]:\n log_probabilities[key] = calculate_log_probability(input_array, summary_item[0], summary_item[1])\n ##################\n\n return log_probabilities"}
{"task_id": "DSP/132", "completion": "def predict(summaries, input_array):\n '''\n Calculates the probability of each data instance belonging to each class value,\n looks for the largest probability, and return the associated class.\n \n Parameters\n ----------\n summaries: A dictionary of numpy arrays\n input_array: A 1d numpy array\n \n Returns\n -------\n A 1d numpy array\n '''\n\n ##################\n # YOUR CODE HERE\n log_prob_temp = list(map(lambda x: calculate_class_log_probabilities(summaries, np.array(x)), input_array))\n log_prob = {}\n for key in summaries:\n temp_list = []\n for index in range(len(input_array)):\n temp_list += log_prob_temp[index][key]\n log_prob[key] = np.array(temp_list)\n best_label = list(range(len(input_array)))\n for index in range(len(input_array)):\n temp_max_label = None\n for key in summaries:\n if (temp_max_label is None) or (log_prob[temp_max_label][index] < log_prob[key][index]):\n temp_max_label = key\n best_label[index] = temp_max_label\n ##################\n\n return best_label"}
{"task_id": "DSP/132", "completion": "def predict(summaries, input_array):\n '''\n Calculates the probability of each data instance belonging to each class value,\n looks for the largest probability, and return the associated class.\n \n Parameters\n ----------\n summaries: A dictionary of numpy arrays\n input_array: A 1d numpy array\n \n Returns\n -------\n A 1d numpy array\n '''\n\n ##################\n # YOUR CODE HERE\n log_prob_temp = list(map(lambda x: calculate_class_log_probabilities(summaries, np.array(x)), input_array))\n log_prob = {}\n for key in summaries:\n temp_list = []\n for index in range(len(input_array)):\n temp_list += log_prob_temp[index][key]\n log_prob[key] = np.array(temp_list)\n best_label = list(range(len(input_array)))\n for index in range(len(input_array)):\n temp_max_label = None\n for key in summaries:\n if (temp_max_label is None) or (log_prob[temp_max_label][index] < log_prob[key][index]):\n temp_max_label = key\n best_label[index] = temp_max_label\n ##################\n\n return best_label"}
{"task_id": "DSP/133", "completion": "nerve_data_url='http://www.stat.cmu.edu/~larry/all-of-statistics/=data/nerve.dat'\ndef read_data(url):\n #url retrieve read the ressource on the server abd save it in the disk\n local_file_name, header = urllib.request.urlretrieve(nerve_data_url) \n return np.fromfile(local_file_name, dtype=float, sep='\t')"}
{"task_id": "DSP/133", "completion": "nerve_data_url='http://www.stat.cmu.edu/~larry/all-of-statistics/=data/nerve.dat'\ndef read_data(url):\n #url retrieve read the ressource on the server abd save it in the disk\n local_file_name, header = urllib.request.urlretrieve(nerve_data_url) \n return np.fromfile(local_file_name, dtype=float, sep='\t')"}
{"task_id": "DSP/134", "completion": "def prob_x(x, data):\n # YOUR CODE HERE\n return len(data[np.where(data <= x)])/len(data)"}
{"task_id": "DSP/134", "completion": "def prob_x(x, data):\n # YOUR CODE HERE\n return len(data[np.where(data <= x)])/len(data)"}
{"task_id": "DSP/135", "completion": "def prob_xy(x,y,data):\n return len(data[np.where(np.logical_and(data > x, data <= y))])/len(data)"}
{"task_id": "DSP/135", "completion": "def prob_xy(x,y,data):\n return len(data[np.where(np.logical_and(data > x, data <= y))])/len(data)"}
{"task_id": "DSP/136", "completion": "def dist_properties(data):\n \"\"\" the\"\"\"\n \"\"\"the skwenss of a distrution is the the third order momen\"\"\"\n stan_dev = np.std(nerve_data)\n mean_ = np.mean(nerve_data)\n skewness =( np.sum(np.power( (nerve_data - mean_), 3)) / len(nerve_data) )/ np.power(stan_dev, 3)\n return np.mean(nerve_data), np.power(stan_dev, 2), skewness"}
{"task_id": "DSP/136", "completion": "def dist_properties(data):\n \"\"\" the\"\"\"\n \"\"\"the skwenss of a distrution is the the third order momen\"\"\"\n stan_dev = np.std(nerve_data)\n mean_ = np.mean(nerve_data)\n skewness =( np.sum(np.power( (nerve_data - mean_), 3)) / len(nerve_data) )/ np.power(stan_dev, 3)\n return np.mean(nerve_data), np.power(stan_dev, 2), skewness"}
{"task_id": "DSP/137", "completion": "def get_string(x,y):\n # YOUR CODE HERE\n return str(x) + str(y)"}
{"task_id": "DSP/137", "completion": "def get_string(x,y):\n # YOUR CODE HERE\n return str(x) + str(y)"}
{"task_id": "DSP/138", "completion": "def ypolynomial(x,p):\n if isinstance(x, (int, float, complex)) and isinstance(p, (int, float, complex)):\n if x < 0:\n return 0\n else:\n return 4 + 5 * np.power(x, p)\n else:\n raise TypeError('I works only with string as input')"}
{"task_id": "DSP/138", "completion": "def ypolynomial(x,p):\n if isinstance(x, (int, float, complex)) and isinstance(p, (int, float, complex)):\n if x < 0:\n return 0\n else:\n return 4 + 5 * np.power(x, p)\n else:\n raise TypeError('I works only with string as input')"}
{"task_id": "DSP/139", "completion": "def divisibles(N, p):\n if isinstance(N, (int, float, complex)) and isinstance(p, (int, float, complex)):\n if N < 0:\n N = 20\n return list(filter(lambda x : x % p == 0, range(N+1)))"}
{"task_id": "DSP/139", "completion": "def divisibles(N, p):\n if isinstance(N, (int, float, complex)) and isinstance(p, (int, float, complex)):\n if N < 0:\n N = 20\n return list(filter(lambda x : x % p == 0, range(N+1)))"}
{"task_id": "DSP/140", "completion": "def divisibles2(s, N, p):\n if isinstance(N, (int, float, complex)) and isinstance(p, (int, float, complex)):\n if N < 0:\n N = 20\n return list(filter(lambda x : x % p == 0, range(s, N+1)))"}
{"task_id": "DSP/140", "completion": "def divisibles2(s, N, p):\n if isinstance(N, (int, float, complex)) and isinstance(p, (int, float, complex)):\n if N < 0:\n N = 20\n return list(filter(lambda x : x % p == 0, range(s, N+1)))"}
{"task_id": "DSP/141", "completion": "def divisibo(N):\n if isinstance(N, int):\n candidate = 1;\n final_candidates = []\n count = 0\n while count < N:\n if ((candidate % 5 ==0) & (candidate % 7 ==0) & (candidate % 11 ==0)):\n count +=1\n final_candidates.append(candidate)\n candidate +=1\n return final_candidates\n else:\n raise TypeError('only works with integer')"}
{"task_id": "DSP/141", "completion": "def divisibo(N):\n if isinstance(N, int):\n candidate = 1;\n final_candidates = []\n count = 0\n while count < N:\n if ((candidate % 5 ==0) & (candidate % 7 ==0) & (candidate % 11 ==0)):\n count +=1\n final_candidates.append(candidate)\n candidate +=1\n return final_candidates\n else:\n raise TypeError('only works with integer')"}
{"task_id": "DSP/142", "completion": "def primes_upto(N):\n \"\"\"\n srieve of erathostene????\n This implies that all the number greater than 1 \n and less than X shouldn\u2019t divide X to remainder 0. (X % num != 0)\n \"\"\"\n if isinstance(N, int):\n sieve = [True] * (N + 1)\n sieve[0:1] = [False, False]\n for start in range(2, N + 1):\n if sieve[start]:\n for i in range(start * start, N + 1, start):\n sieve[i] = False\n primes = []\n for i in range(2, N + 1):\n if sieve[i]:\n primes.append(i)\n return primes\n else:\n raise TypeError('Only works with integer')"}
{"task_id": "DSP/142", "completion": "def primes_upto(N):\n \"\"\"\n srieve of erathostene????\n This implies that all the number greater than 1 \n and less than X shouldn\u2019t divide X to remainder 0. (X % num != 0)\n \"\"\"\n if isinstance(N, int):\n sieve = [True] * (N + 1)\n sieve[0:1] = [False, False]\n for start in range(2, N + 1):\n if sieve[start]:\n for i in range(start * start, N + 1, start):\n sieve[i] = False\n primes = []\n for i in range(2, N + 1):\n if sieve[i]:\n primes.append(i)\n return primes\n else:\n raise TypeError('Only works with integer')"}
{"task_id": "DSP/143", "completion": "def primes_first(N):\n def is_prime(n):\n if n % 2 == 0 and n > 2: \n return False\n return all(n % i for i in range(3, int(np.sqrt(n)) + 1, 2))\n if isinstance(N, int):\n candidate = 2;\n final_candidates = []\n count = 0\n while count < N:\n if (is_prime(candidate)):\n count +=1\n final_candidates.append(candidate)\n candidate +=1\n return final_candidates\n else:\n raise TypeError('only works with integer')"}
{"task_id": "DSP/143", "completion": "def primes_first(N):\n def is_prime(n):\n if n % 2 == 0 and n > 2: \n return False\n return all(n % i for i in range(3, int(np.sqrt(n)) + 1, 2))\n if isinstance(N, int):\n candidate = 2;\n final_candidates = []\n count = 0\n while count < N:\n if (is_prime(candidate)):\n count +=1\n final_candidates.append(candidate)\n candidate +=1\n return final_candidates\n else:\n raise TypeError('only works with integer')"}
{"task_id": "DSP/144", "completion": "def flatten_list(superlist):\n \"\"\"\n Make an iterator that returns elements from the first iterable until it is exhausted, \n then proceeds to the next iterable, until all of the iterables are exhausted. \n Used for treating consecutive sequences as a single sequence:\n \"\"\"\n from collections import Iterable\n from itertools import chain\n if isinstance(superlist, Iterable):\n return sorted(list(chain.from_iterable(superlist)))\n else :\n raise TypeError('Accept only list')"}
{"task_id": "DSP/144", "completion": "def flatten_list(superlist):\n \"\"\"\n Make an iterator that returns elements from the first iterable until it is exhausted, \n then proceeds to the next iterable, until all of the iterables are exhausted. \n Used for treating consecutive sequences as a single sequence:\n \"\"\"\n from collections import Iterable\n from itertools import chain\n if isinstance(superlist, Iterable):\n return sorted(list(chain.from_iterable(superlist)))\n else :\n raise TypeError('Accept only list')"}
{"task_id": "DSP/145", "completion": "def longest_word(text):\n \"\"\"implement a merge sort from scratch???\n \"\"\"\n if isinstance(text, str):\n text_list = text.split(' ')\n m = max(list(map(len, text_list)))\n return [x for x in text_list if len(x) == m][0]\n else :\n raise TypeError('Only works with string ')"}
{"task_id": "DSP/145", "completion": "def longest_word(text):\n \"\"\"implement a merge sort from scratch???\n \"\"\"\n if isinstance(text, str):\n text_list = text.split(' ')\n m = max(list(map(len, text_list)))\n return [x for x in text_list if len(x) == m][0]\n else :\n raise TypeError('Only works with string ')"}
{"task_id": "DSP/146", "completion": "def dictionarize(alist):\n if isinstance(alist, list):\n from collections import Counter\n return Counter(alist)\n else:\n raise TypeError('Only works with list')"}
{"task_id": "DSP/146", "completion": "def dictionarize(alist):\n if isinstance(alist, list):\n from collections import Counter\n return Counter(alist)\n else:\n raise TypeError('Only works with list')"}
{"task_id": "DSP/147", "completion": "def valid_markings(solution, graph):\n marked = []\n for idx, i in enumerate(solution):\n if i == 1:\n #add elme,t as marked by him\n for edx_j, j in enumerate(graph[i]):\n if graph[idx][edx_j] == 1:\n marked.append(edx_j)\n return list(set(marked)) == list(range(0, len(graph)))"}
{"task_id": "DSP/147", "completion": "def valid_markings(solution, graph):\n marked = []\n for idx, i in enumerate(solution):\n if i == 1:\n #add elme,t as marked by him\n for edx_j, j in enumerate(graph[i]):\n if graph[idx][edx_j] == 1:\n marked.append(edx_j)\n return list(set(marked)) == list(range(0, len(graph)))"}
{"task_id": "DSP/148", "completion": "def optimal_markings(input_graph):\n \"\"\"\n the following function will return the most optimal marking for an input \n graph , \n to do it we will try all possibles marking , and check if they are valid markings by using the previous function\n once all valid marking are found , we need to sort them according to the number of element it need to do,marking\n the most optimal marking are the marking with the lowest 1 elements\n \"\"\"\n results_counts = []\n for combination in itertools.product([1, 0], repeat=len(input_graph)):\n results = combination\n if valid_markings(results, input_graph):\n results_counts.append((results.count(1), results))\n optimal_required = sorted(results_counts, key = lambda x : x[0] )[0][0]\n optimal_marking = list(filter( lambda x : x[0] == optimal_required, results_counts))\n return optimal_marking[0]"}
{"task_id": "DSP/148", "completion": "def optimal_markings(input_graph):\n \"\"\"\n the following function will return the most optimal marking for an input \n graph , \n to do it we will try all possibles marking , and check if they are valid markings by using the previous function\n once all valid marking are found , we need to sort them according to the number of element it need to do,marking\n the most optimal marking are the marking with the lowest 1 elements\n \"\"\"\n results_counts = []\n for combination in itertools.product([1, 0], repeat=len(input_graph)):\n results = combination\n if valid_markings(results, input_graph):\n results_counts.append((results.count(1), results))\n optimal_required = sorted(results_counts, key = lambda x : x[0] )[0][0]\n optimal_marking = list(filter( lambda x : x[0] == optimal_required, results_counts))\n return optimal_marking[0]"}
{"task_id": "DSP/149", "completion": "def incr_list_by_1(x):\n return [i+1 for i in x]"}
{"task_id": "DSP/149", "completion": "def incr_list_by_1(x):\n return [i+1 for i in x]"}
{"task_id": "DSP/150", "completion": "def change_evens_to_zeros(list):\n try:\n return [0 if i % 2 == 0 else i for i in list]\n except TypeError as err_msg:\n return 'Can not transform list with non-numeric elements'"}
{"task_id": "DSP/150", "completion": "def change_evens_to_zeros(list):\n try:\n return [0 if i % 2 == 0 else i for i in list]\n except TypeError as err_msg:\n return 'Can not transform list with non-numeric elements'"}
{"task_id": "DSP/151", "completion": "def same_digits(x, y):\n \"\"\"Do the integers x and y have the same digits, regardless of order.\"\"\"\n if len(x) != len(y):\n return False\n isSame = True\n sameCount = 0\n for d1 in str(x):\n for d2 in str(y):\n if d1 == d2:\n sameCount += 1\n break;\n if sameCount != len(x):\n isSame = False\n return isSame"}
{"task_id": "DSP/151", "completion": "def same_digits(x, y):\n \"\"\"Do the integers x and y have the same digits, regardless of order.\"\"\"\n if len(x) != len(y):\n return False\n isSame = True\n sameCount = 0\n for d1 in str(x):\n for d2 in str(y):\n if d1 == d2:\n sameCount += 1\n break;\n if sameCount != len(x):\n isSame = False\n return isSame"}
{"task_id": "DSP/152", "completion": "data = np.genfromtxt('data/open_exoplanet_catalogue.txt', delimiter=',')"}
{"task_id": "DSP/152", "completion": "data = np.genfromtxt('data/open_exoplanet_catalogue.txt', delimiter=',')"}
{"task_id": "DSP/153", "completion": "s4 = df1.iloc[0::2]['cell_phone']\n#s4 = s4['cell_phone']\ns4"}
{"task_id": "DSP/153", "completion": "s4 = df1.iloc[0::2]['cell_phone']\n#s4 = s4['cell_phone']\ns4"}
{"task_id": "DSP/154", "completion": "ce = create_engine('sqlite:///data/Chinook_Sqlite.sqlite')"}
{"task_id": "DSP/154", "completion": "ce = create_engine('sqlite:///data/Chinook_Sqlite.sqlite')"}
{"task_id": "DSP/155", "completion": "inspector = inspect(ce)"}
{"task_id": "DSP/155", "completion": "inspector = inspect(ce)"}
{"task_id": "DSP/156", "completion": "t1 = table_info('Genre', inspector)"}
{"task_id": "DSP/156", "completion": "t1 = table_info('Genre', inspector)"}
{"task_id": "DSP/157", "completion": "t2 = sql.read_sql_query(\"\"\"\n SELECT *\n FROM genre\n LIMIT 10;\n\"\"\", ce)"}
{"task_id": "DSP/157", "completion": "t2 = sql.read_sql_query(\"\"\"\n SELECT *\n FROM genre\n LIMIT 10;\n\"\"\", ce)"}
{"task_id": "DSP/158", "completion": "t3 = table_info('Track', inspector)"}
{"task_id": "DSP/158", "completion": "t3 = table_info('Track', inspector)"}
{"task_id": "DSP/159", "completion": "t4 = sql.read_sql_query(\"\"\"\n SELECT *\n FROM track\n LIMIT 10;\n\"\"\", ce)"}
{"task_id": "DSP/159", "completion": "t4 = sql.read_sql_query(\"\"\"\n SELECT *\n FROM track\n LIMIT 10;\n\"\"\", ce)"}
{"task_id": "DSP/160", "completion": "t5 = table_info('MediaType', inspector)"}
{"task_id": "DSP/160", "completion": "t5 = table_info('MediaType', inspector)"}
{"task_id": "DSP/161", "completion": "t6 = sql.read_sql_query(\"\"\"\n SELECT *\n FROM mediatype\n LIMIT 10;\n\"\"\", ce)"}
{"task_id": "DSP/161", "completion": "t6 = sql.read_sql_query(\"\"\"\n SELECT *\n FROM mediatype\n LIMIT 10;\n\"\"\", ce)"}
{"task_id": "DSP/162", "completion": "t7 = sql.read_sql_query(\"\"\"\n SELECT name, composer, unitPrice\n FROM track\n WHERE unitPrice > 0.99\n\"\"\", ce)"}
{"task_id": "DSP/162", "completion": "t7 = sql.read_sql_query(\"\"\"\n SELECT name, composer, unitPrice\n FROM track\n WHERE unitPrice > 0.99\n\"\"\", ce)"}
{"task_id": "DSP/163", "completion": "j2 = sql.read_sql_query(\"\"\"\n SELECT MediaType.name, COUNT(MediaType.name) AS Count\n FROM MediaType\n INNER JOIN Track\n ON Track.mediaTypeID = MediaType.mediaTypeID\n GROUP BY MediaType.name\n ORDER BY Count\n\"\"\", ce)"}
{"task_id": "DSP/163", "completion": "j2 = sql.read_sql_query(\"\"\"\n SELECT MediaType.name, COUNT(MediaType.name) AS Count\n FROM MediaType\n INNER JOIN Track\n ON Track.mediaTypeID = MediaType.mediaTypeID\n GROUP BY MediaType.name\n ORDER BY Count\n\"\"\", ce)"}
{"task_id": "DSP/164", "completion": "def soliton(x, t, c, a):\n \"\"\"Return phi(x, t) for a soliton wave with constants c and a.\"\"\"\n coeff = .5 * c\n cosh = np.cosh((c**(-.5)*.5)*(x - c * t - a))\n f = 1 / np.power(cosh, 2)\n phi = coeff * f\n return phi"}
{"task_id": "DSP/164", "completion": "def soliton(x, t, c, a):\n \"\"\"Return phi(x, t) for a soliton wave with constants c and a.\"\"\"\n coeff = .5 * c\n cosh = np.cosh((c**(-.5)*.5)*(x - c * t - a))\n f = 1 / np.power(cosh, 2)\n phi = coeff * f\n return phi"}
{"task_id": "DSP/165", "completion": "phi = soliton(xn, tn, c, a)"}
{"task_id": "DSP/165", "completion": "phi = soliton(xn, tn, c, a)"}
{"task_id": "DSP/166", "completion": "df2 = df.dropna()"}
{"task_id": "DSP/166", "completion": "df2 = df.dropna()"}
{"task_id": "DSP/167", "completion": "df5 = df5.fillna(-9)\n#df5"}
{"task_id": "DSP/167", "completion": "df5 = df5.fillna(-9)\n#df5"}
{"task_id": "DSP/168", "completion": "def uniform2(mu, sigma, size=1):\n \"\"\"Return uniform random variates with mean mu and standard dev sigma.\"\"\"\n d = np.sqrt(3*sigma**2)\n a = mu - d\n b = mu + d\n n = np.random.uniform(a, b, size)\n return n"}
{"task_id": "DSP/168", "completion": "def uniform2(mu, sigma, size=1):\n \"\"\"Return uniform random variates with mean mu and standard dev sigma.\"\"\"\n d = np.sqrt(3*sigma**2)\n a = mu - d\n b = mu + d\n n = np.random.uniform(a, b, size)\n return n"}
{"task_id": "DSP/169", "completion": "np.random.seed(0) # keep this line to reset the random number generator\nsim1 = np.random.poisson(t1_avg, n)\nsim2 = np.random.poisson(t2_avg, n)"}
{"task_id": "DSP/169", "completion": "np.random.seed(0) # keep this line to reset the random number generator\nsim1 = np.random.poisson(t1_avg, n)\nsim2 = np.random.poisson(t2_avg, n)"}
{"task_id": "DSP/170", "completion": "spread = sim2 - sim1"}
{"task_id": "DSP/170", "completion": "spread = sim2 - sim1"}
{"task_id": "DSP/171", "completion": "def vector_sum(x, y):\n \"\"\"Compute the vector sum of x and y as a Python list.\"\"\"\n assert len(x)==len(y)\n i = 0\n Vlen = len(x)\n Vsum = []\n while i < Vlen: #could use len(x) directly\n Vsum.append(x[i] + y[i])\n i += 1\n return Vsum"}
{"task_id": "DSP/171", "completion": "def vector_sum(x, y):\n \"\"\"Compute the vector sum of x and y as a Python list.\"\"\"\n assert len(x)==len(y)\n i = 0\n Vlen = len(x)\n Vsum = []\n while i < Vlen: #could use len(x) directly\n Vsum.append(x[i] + y[i])\n i += 1\n return Vsum"}
{"task_id": "DSP/172", "completion": "def vector_diff(x, y):\n \"\"\"Compute the vector difference of x and y as a Python list.\"\"\"\n assert len(x)==len(y)\n i = 0\n Vlen = len(x)\n Vsum = []\n while i < Vlen:\n Vsum.append(x[i] - y[i])\n i += 1\n return Vsum"}
{"task_id": "DSP/172", "completion": "def vector_diff(x, y):\n \"\"\"Compute the vector difference of x and y as a Python list.\"\"\"\n assert len(x)==len(y)\n i = 0\n Vlen = len(x)\n Vsum = []\n while i < Vlen:\n Vsum.append(x[i] - y[i])\n i += 1\n return Vsum"}
{"task_id": "DSP/173", "completion": "def vector_scalar_mul(a, x):\n \"\"\"Compute a*x as a Python list.\"\"\"\n i = 0\n Vlen = len(x)\n Vsum = []\n while i < Vlen:\n Vsum.append(x[i] * a)\n i += 1\n return Vsum"}
{"task_id": "DSP/173", "completion": "def vector_scalar_mul(a, x):\n \"\"\"Compute a*x as a Python list.\"\"\"\n i = 0\n Vlen = len(x)\n Vsum = []\n while i < Vlen:\n Vsum.append(x[i] * a)\n i += 1\n return Vsum"}
{"task_id": "DSP/174", "completion": "def vector_dot(x, y):\n \"\"\"Compute the dot product of vectors a and b.\"\"\"\n assert len(x)==len(y)\n i = 0\n Vlen = len(x)\n Vsum = []\n while i < Vlen:\n Vsum.append(x[i] * y[i])\n i += 1\n return sum(Vsum)"}
{"task_id": "DSP/174", "completion": "def vector_dot(x, y):\n \"\"\"Compute the dot product of vectors a and b.\"\"\"\n assert len(x)==len(y)\n i = 0\n Vlen = len(x)\n Vsum = []\n while i < Vlen:\n Vsum.append(x[i] * y[i])\n i += 1\n return sum(Vsum)"}
{"task_id": "DSP/175", "completion": "def L1(x):\n \"\"\"Compute the L1 norm of x.\"\"\"\n norm = 0\n Vlen = len(x)\n i = 0\n while i < Vlen:\n norm += abs(x[i])\n i += 1\n return norm"}
{"task_id": "DSP/175", "completion": "def L1(x):\n \"\"\"Compute the L1 norm of x.\"\"\"\n norm = 0\n Vlen = len(x)\n i = 0\n while i < Vlen:\n norm += abs(x[i])\n i += 1\n return norm"}
{"task_id": "DSP/176", "completion": "def L2(x):\n \"\"\"Compute the L2 norm of x.\"\"\"\n norm = 0\n Vlen = len(x)\n i = 0\n ans = 0\n while i < Vlen:\n norm += x[i] **2\n i += 1\n ans = math.sqrt(norm)\n return ans"}
{"task_id": "DSP/176", "completion": "def L2(x):\n \"\"\"Compute the L2 norm of x.\"\"\"\n norm = 0\n Vlen = len(x)\n i = 0\n ans = 0\n while i < Vlen:\n norm += x[i] **2\n i += 1\n ans = math.sqrt(norm)\n return ans"}
{"task_id": "DSP/177", "completion": "def mse(x, y):\n \"\"\"Compute the mean squared error between x and y.\"\"\"\n i = 0\n L = []\n while i < len(x):\n sub = x[i] - y[i]\n L.append(sub **2)\n i += 1\n return sum(L) / len(x)"}
{"task_id": "DSP/177", "completion": "def mse(x, y):\n \"\"\"Compute the mean squared error between x and y.\"\"\"\n i = 0\n L = []\n while i < len(x):\n sub = x[i] - y[i]\n L.append(sub **2)\n i += 1\n return sum(L) / len(x)"}
{"task_id": "DSP/178", "completion": "def mean(x):\n \"\"\"Compute the mean of the elements of x.\"\"\"\n return sum(x) / len(x)"}
{"task_id": "DSP/178", "completion": "def mean(x):\n \"\"\"Compute the mean of the elements of x.\"\"\"\n return sum(x) / len(x)"}
{"task_id": "DSP/179", "completion": "def var(x):\n \"\"\"Compute the variance of the elements of x.\"\"\"\n ans = 0\n i = 0\n while i < len(x):\n ans += ((x[i] - mean(x)) **2)\n i += 1\n return ans / len(x)"}
{"task_id": "DSP/179", "completion": "def var(x):\n \"\"\"Compute the variance of the elements of x.\"\"\"\n ans = 0\n i = 0\n while i < len(x):\n ans += ((x[i] - mean(x)) **2)\n i += 1\n return ans / len(x)"}
{"task_id": "DSP/180", "completion": "def std(x):\n \"\"\"Compute the standard deviation of the elements of x.\"\"\"\n return math.sqrt(var(x))"}
{"task_id": "DSP/180", "completion": "def std(x):\n \"\"\"Compute the standard deviation of the elements of x.\"\"\"\n return math.sqrt(var(x))"}
{"task_id": "DSP/181", "completion": "(t, W) = wiener(1.0, 1000)\nlen(W)"}
{"task_id": "DSP/181", "completion": "(t, W) = wiener(1.0, 1000)\nlen(W)"}
{"task_id": "DSP/182", "completion": "mpg_data = None\nmpg_data = pd.read_fwf(\"http://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data\", header = None)\nmpg_data.columns = [\"mpg\", \"cylinders\", \"displacement\", \"horsepower\", \"weight\", \"acceleration\", \"model_year\", \"origin\", \"car_name\"]"}
{"task_id": "DSP/182", "completion": "mpg_data = None\nmpg_data = pd.read_fwf(\"http://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data\", header = None)\nmpg_data.columns = [\"mpg\", \"cylinders\", \"displacement\", \"horsepower\", \"weight\", \"acceleration\", \"model_year\", \"origin\", \"car_name\"]"}
{"task_id": "DSP/183", "completion": "mpg_data.horsepower = mpg_data.horsepower.astype(float)\nmpg_data.horsepower.unique()"}
{"task_id": "DSP/183", "completion": "mpg_data.horsepower = mpg_data.horsepower.astype(float)\nmpg_data.horsepower.unique()"}
{"task_id": "DSP/184", "completion": "mpg_data = mpg_data.drop(mpg_data[pd.isnull(mpg_data['horsepower'])].index)"}
{"task_id": "DSP/184", "completion": "mpg_data = mpg_data.drop(mpg_data[pd.isnull(mpg_data['horsepower'])].index)"}
{"task_id": "DSP/185", "completion": "def calculate_correlation(dataframe, first_column, second_column):\n \"\"\"\n Calculates and returns the correlation coefficient between the two columns in the dataframe.\n \"\"\"\n correlation = dataframe[first_column].corr(dataframe[second_column])\n return correlation"}
{"task_id": "DSP/185", "completion": "def calculate_correlation(dataframe, first_column, second_column):\n \"\"\"\n Calculates and returns the correlation coefficient between the two columns in the dataframe.\n \"\"\"\n correlation = dataframe[first_column].corr(dataframe[second_column])\n return correlation"}
{"task_id": "DSP/186", "completion": "income_data = pd.read_csv(\"https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data\", header = None, sep = \", \")\nincome_data.columns = [\"age\", \"workclass\", \"fnlwgt\", \"education\", \"education_num\", \"marital_status\", \"occupation\", \"relationship\", \"race\", \"sex\", \"capital_gain\", \"capital_loss\", \"hours_per_week\", \"native_country\", \"label\"\n]\nincome_data.head()"}
{"task_id": "DSP/186", "completion": "income_data = pd.read_csv(\"https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data\", header = None, sep = \", \")\nincome_data.columns = [\"age\", \"workclass\", \"fnlwgt\", \"education\", \"education_num\", \"marital_status\", \"occupation\", \"relationship\", \"race\", \"sex\", \"capital_gain\", \"capital_loss\", \"hours_per_week\", \"native_country\", \"label\"\n]\nincome_data.head()"}
{"task_id": "DSP/187", "completion": "def get_mean_working_hours_by_income(dataframe):\n grouped = dataframe.groupby('occupation')['hours_per_week'].mean()\n \n return grouped.sort_values(ascending = False)"}
{"task_id": "DSP/187", "completion": "def get_mean_working_hours_by_income(dataframe):\n grouped = dataframe.groupby('occupation')['hours_per_week'].mean()\n \n return grouped.sort_values(ascending = False)"}
{"task_id": "DSP/188", "completion": "titanic_data = pd.read_csv(\"data/titanic.csv\")\ntitanic_data.set_index('PassengerId', inplace = True)\ntitanic_data.rename(columns = {\"Pclass\": \"Class\", \"Parch\": \"ParCh\"}, inplace = True)\ntitanic_data.loc[titanic_data.Embarked == 'C', 'Embarked'] = 'Cherbourg'\ntitanic_data.loc[titanic_data.Embarked == 'Q', 'Embarked'] = 'Queenstown'\ntitanic_data.loc[titanic_data.Embarked == 'S', 'Embarked'] = 'Southampton'\n\ntitanic_data.head()"}
{"task_id": "DSP/188", "completion": "titanic_data = pd.read_csv(\"data/titanic.csv\")\ntitanic_data.set_index('PassengerId', inplace = True)\ntitanic_data.rename(columns = {\"Pclass\": \"Class\", \"Parch\": \"ParCh\"}, inplace = True)\ntitanic_data.loc[titanic_data.Embarked == 'C', 'Embarked'] = 'Cherbourg'\ntitanic_data.loc[titanic_data.Embarked == 'Q', 'Embarked'] = 'Queenstown'\ntitanic_data.loc[titanic_data.Embarked == 'S', 'Embarked'] = 'Southampton'\n\ntitanic_data.head()"}
{"task_id": "DSP/189", "completion": "ages_by_class = titanic_data.groupby('Class')['Age']"}
{"task_id": "DSP/189", "completion": "ages_by_class = titanic_data.groupby('Class')['Age']"}
{"task_id": "DSP/190", "completion": "test_result = ttest_ind(first_class_ages, third_class_ages)\n\nprint(test_result.pvalue)\nif test_result.pvalue <= 0.01:\n print(\"The differences in age are significant. Reject H0.\")\nelse:\n print(\"There's not enough evidence to reject H0. Don't accept or reject anything else.\")"}
{"task_id": "DSP/190", "completion": "test_result = ttest_ind(first_class_ages, third_class_ages)\n\nprint(test_result.pvalue)\nif test_result.pvalue <= 0.01:\n print(\"The differences in age are significant. Reject H0.\")\nelse:\n print(\"There's not enough evidence to reject H0. Don't accept or reject anything else.\")"}
{"task_id": "DSP/191", "completion": "titanic_data_for_modelling.drop(\"Sex_female\", axis = 1, inplace = True)"}
{"task_id": "DSP/191", "completion": "titanic_data_for_modelling.drop(\"Sex_female\", axis = 1, inplace = True)"}
{"task_id": "DSP/192", "completion": "scaler = MinMaxScaler()\ntitanic_data_features_scaled = scaler.fit_transform(titanic_data_features)"}
{"task_id": "DSP/192", "completion": "scaler = MinMaxScaler()\ntitanic_data_features_scaled = scaler.fit_transform(titanic_data_features)"}
{"task_id": "DSP/193", "completion": "model = LogisticRegression()\nmodel.fit(features_train, target_train)"}
{"task_id": "DSP/193", "completion": "model = LogisticRegression()\nmodel.fit(features_train, target_train)"}
{"task_id": "DSP/194", "completion": "score = model.score(features_test, target_test)\nscore"}
{"task_id": "DSP/194", "completion": "score = model.score(features_test, target_test)\nscore"}
{"task_id": "DSP/195", "completion": "def resize_images(images):\n \"\"\"\n Resizes all images to have the same width\n \"\"\"\n max_width = max([image.shape[1] for image in images])\n padded_images = [np.pad(image, ((0, 0), (0, max_width - image.shape[1])), mode = \"constant\", constant_values = 255) for image in images]\n return padded_images\n\ndef concatenate_images(images):\n \"\"\"\n Concatenates all images vertically (one below the other)\n \"\"\"\n return np.vstack(resize_images(images))"}
{"task_id": "DSP/195", "completion": "def resize_images(images):\n \"\"\"\n Resizes all images to have the same width\n \"\"\"\n max_width = max([image.shape[1] for image in images])\n padded_images = [np.pad(image, ((0, 0), (0, max_width - image.shape[1])), mode = \"constant\", constant_values = 255) for image in images]\n return padded_images\n\ndef concatenate_images(images):\n \"\"\"\n Concatenates all images vertically (one below the other)\n \"\"\"\n return np.vstack(resize_images(images))"}
{"task_id": "DSP/196", "completion": "menu_content = \"\"\nwith open(\"output/menu.txt\", \"r\", encoding = \"utf-8\") as f:\n menu_content = f.read()\n\nprint(menu_content)"}
{"task_id": "DSP/196", "completion": "menu_content = \"\"\nwith open(\"output/menu.txt\", \"r\", encoding = \"utf-8\") as f:\n menu_content = f.read()\n\nprint(menu_content)"}
{"task_id": "DSP/197", "completion": "meals_string = menu_content[:menu_content.index(\"Wine by the Glass\")]\ndef generate_meals_table(meals_string):\n df = pd.read_csv(io.StringIO(meals_string), sep=\"|\", header=None)\n df.columns = ['category', 'meal_name', 'price']\n df['category'] = df['category'].str.lower()\n\n return df"}
{"task_id": "DSP/197", "completion": "meals_string = menu_content[:menu_content.index(\"Wine by the Glass\")]\ndef generate_meals_table(meals_string):\n df = pd.read_csv(io.StringIO(meals_string), sep=\"|\", header=None)\n df.columns = ['category', 'meal_name', 'price']\n df['category'] = df['category'].str.lower()\n\n return df"}
{"task_id": "DSP/198", "completion": "num_items_total = meals_table.shape[0]\nnum_categories_total = meals_table.category.nunique()\nnum_items_by_category = meals_table.groupby(['category'])['meal_name'].count()\nmean_price_by_category = meals_table.groupby(['category'])['price'].mean()"}
{"task_id": "DSP/198", "completion": "num_items_total = meals_table.shape[0]\nnum_categories_total = meals_table.category.nunique()\nnum_items_by_category = meals_table.groupby(['category'])['meal_name'].count()\nmean_price_by_category = meals_table.groupby(['category'])['price'].mean()"}
{"task_id": "DSP/199", "completion": "def simulate(transitions):\n # >>>>> YOUR CODE HERE\n import random\n random.seed(123)\n state_sequence = []\n current_state = 'A'\n for i in range(1999):\n r = random.randint(0, 2)\n current_state = transitions[current_state][r % len(transitions[current_state])]\n state_sequence.append(current_state)\n # <<<<< END YOUR CODE\n return state_sequence"}
{"task_id": "DSP/199", "completion": "def simulate(transitions):\n # >>>>> YOUR CODE HERE\n import random\n random.seed(123)\n state_sequence = []\n current_state = 'A'\n for i in range(1999):\n r = random.randint(0, 2)\n current_state = transitions[current_state][r % len(transitions[current_state])]\n state_sequence.append(current_state)\n # <<<<< END YOUR CODE\n return state_sequence"}
{"task_id": "DSP/200", "completion": "def compute_histogram(state_sequence):\n # >>>>> YOUR CODE HERE\n histogram = [state_sequence.count(state) / len(state_sequence) for state in S]\n # <<<<< END YOUR CODE\n return histogram"}
{"task_id": "DSP/200", "completion": "def compute_histogram(state_sequence):\n # >>>>> YOUR CODE HERE\n histogram = [state_sequence.count(state) / len(state_sequence) for state in S]\n # <<<<< END YOUR CODE\n return histogram"}
{"task_id": "DSP/201", "completion": "def get_stationary(matrix):\n # >>>>> YOUR CODE HERE\n import utils\n stationary_distribution = utils.getstationary(matrix)\n # <<<<< END YOUR CODE\n return stationary_distribution"}
{"task_id": "DSP/201", "completion": "def get_stationary(matrix):\n # >>>>> YOUR CODE HERE\n import utils\n stationary_distribution = utils.getstationary(matrix)\n # <<<<< END YOUR CODE\n return stationary_distribution"}
{"task_id": "DSP/202", "completion": "import utils\nP = build_transition_matrix()\nutils.getstationary(P)\n# <<<<< END YOUR CODE"}
{"task_id": "DSP/202", "completion": "import utils\nP = build_transition_matrix()\nutils.getstationary(P)\n# <<<<< END YOUR CODE"}
{"task_id": "DSP/203", "completion": "def simulate_1000():\n # >>>>> YOUR CODE HERE\n import utils\n initial_states = utils.getinitialstate() # 1000 x 8 initial state in 1000 trials\n transitions = build_transition_matrix() # transitions\n pad_shape = ((0, 0), (1, 0)) \n transitions = numpy.pad(transitions, pad_shape, mode='constant')\n for time_step in range(500):\n initial_states = utils.mcstep(initial_states, transitions, time_step)\n state_amount = transitions.shape[0]\n estimated_stationary_distribution = numpy.zeros(state_amount)\n for state in range(state_amount):\n estimated_stationary_distribution[state] = numpy.count_nonzero(initial_states[:,state]) / initial_states.shape[0]\n # <<<<< END YOUR CODE\n return estimated_stationary_distribution"}
{"task_id": "DSP/203", "completion": "def simulate_1000():\n # >>>>> YOUR CODE HERE\n import utils\n initial_states = utils.getinitialstate() # 1000 x 8 initial state in 1000 trials\n transitions = build_transition_matrix() # transitions\n pad_shape = ((0, 0), (1, 0)) \n transitions = numpy.pad(transitions, pad_shape, mode='constant')\n for time_step in range(500):\n initial_states = utils.mcstep(initial_states, transitions, time_step)\n state_amount = transitions.shape[0]\n estimated_stationary_distribution = numpy.zeros(state_amount)\n for state in range(state_amount):\n estimated_stationary_distribution[state] = numpy.count_nonzero(initial_states[:,state]) / initial_states.shape[0]\n # <<<<< END YOUR CODE\n return estimated_stationary_distribution"}
{"task_id": "DSP/204", "completion": "def simulate(transitions):\n # >>>>> YOUR CODE HERE\n import random\n random.seed(123)\n state_sequence = []\n current_state = 'A'\n for i in range(1999):\n r = random.randint(0, 2)\n current_state = transitions[current_state][r % len(transitions[current_state])]\n state_sequence.append(current_state)\n # <<<<< END YOUR CODE\n return state_sequence"}
{"task_id": "DSP/204", "completion": "def simulate(transitions):\n # >>>>> YOUR CODE HERE\n import random\n random.seed(123)\n state_sequence = []\n current_state = 'A'\n for i in range(1999):\n r = random.randint(0, 2)\n current_state = transitions[current_state][r % len(transitions[current_state])]\n state_sequence.append(current_state)\n # <<<<< END YOUR CODE\n return state_sequence"}
{"task_id": "DSP/205", "completion": "def compute_histogram(state_sequence):\n # >>>>> YOUR CODE HERE\n histogram = [state_sequence.count(state) / len(state_sequence) for state in S]\n # <<<<< END YOUR CODE\n return histogram"}
{"task_id": "DSP/205", "completion": "def compute_histogram(state_sequence):\n # >>>>> YOUR CODE HERE\n histogram = [state_sequence.count(state) / len(state_sequence) for state in S]\n # <<<<< END YOUR CODE\n return histogram"}
{"task_id": "DSP/206", "completion": "def get_stationary(matrix):\n # >>>>> YOUR CODE HERE\n import utils\n stationary_distribution = utils.getstationary(matrix)\n # <<<<< END YOUR CODE\n return stationary_distribution"}
{"task_id": "DSP/206", "completion": "def get_stationary(matrix):\n # >>>>> YOUR CODE HERE\n import utils\n stationary_distribution = utils.getstationary(matrix)\n # <<<<< END YOUR CODE\n return stationary_distribution"}
{"task_id": "DSP/207", "completion": "import utils\nP = build_transition_matrix()\nutils.getstationary(P)\n# <<<<< END YOUR CODE"}
{"task_id": "DSP/207", "completion": "import utils\nP = build_transition_matrix()\nutils.getstationary(P)\n# <<<<< END YOUR CODE"}
{"task_id": "DSP/208", "completion": "def simulate_1000():\n # >>>>> YOUR CODE HERE\n import utils\n X = utils.getinitialstate()\n P = build_transition_matrix()\n pad_shape = ((0, 0), (1, 0)) \n P = numpy.pad(P, pad_shape, mode='constant')\n for i in range(500):\n X = utils.mcstep(X, P, i)\n n = P.shape[0]\n estimated_stationary_distribution = numpy.zeros(n)\n for i in range(n):\n estimated_stationary_distribution[i] = numpy.count_nonzero(X[:,i]) / X.shape[0]\n # <<<<< END YOUR CODE\n return estimated_stationary_distribution"}
{"task_id": "DSP/208", "completion": "def simulate_1000():\n # >>>>> YOUR CODE HERE\n import utils\n X = utils.getinitialstate()\n P = build_transition_matrix()\n pad_shape = ((0, 0), (1, 0)) \n P = numpy.pad(P, pad_shape, mode='constant')\n for i in range(500):\n X = utils.mcstep(X, P, i)\n n = P.shape[0]\n estimated_stationary_distribution = numpy.zeros(n)\n for i in range(n):\n estimated_stationary_distribution[i] = numpy.count_nonzero(X[:,i]) / X.shape[0]\n # <<<<< END YOUR CODE\n return estimated_stationary_distribution"}
{"task_id": "DSP/209", "completion": "import pickle, gzip\n\n# YOUR CODE HERE\ndef write_pickle(obj, destination=\"temp.pickle\", write_over=True):\n \"\"\"\n Saves an object to a compressed pickle file\n Arguments:\n obj: the object to pickle\n destination: the destination of the pickle file\n write_over: a flag that if True will write over an existing file and if False will raise a `FileExistsError`` if a file with that name exists\n Returns:\n p_file: the pickled file\n \n \"\"\"\n directoryFiles = os.listdir(os.getcwd())\n if destination in directoryFiles:\n if write_over == True:\n f=gzip.open(destination,'wb')\n pickle.dump(obj,f) \n f.close()\n else:\n raise FileExistsError\n else:\n f=gzip.open(destination,'wb')\n pickle.dump(obj,f) \n f.close()"}
{"task_id": "DSP/209", "completion": "import pickle, gzip\n\n# YOUR CODE HERE\ndef write_pickle(obj, destination=\"temp.pickle\", write_over=True):\n \"\"\"\n Saves an object to a compressed pickle file\n Arguments:\n obj: the object to pickle\n destination: the destination of the pickle file\n write_over: a flag that if True will write over an existing file and if False will raise a `FileExistsError`` if a file with that name exists\n Returns:\n p_file: the pickled file\n \n \"\"\"\n directoryFiles = os.listdir(os.getcwd())\n if destination in directoryFiles:\n if write_over == True:\n f=gzip.open(destination,'wb')\n pickle.dump(obj,f) \n f.close()\n else:\n raise FileExistsError\n else:\n f=gzip.open(destination,'wb')\n pickle.dump(obj,f) \n f.close()"}
{"task_id": "DSP/210", "completion": "import numpy as np\nimport numbers\n\ndef d1a(s, h=1):\n \"\"\"\n Computes the 1st derivative of a 1-D numpy array using a backward difference approximation of the derivative.\n Arguments:\n s: the 1-D numpy array we will take the first derivative of.\n h: the unit step size (i.e. what the length of one step in the array represents).\n Returns:\n d1: thd 1st derivative of s.\n \"\"\"\n if not isinstance(s, np.ndarray) or not isinstance(h, numbers.Number):\n raise TypeError\n elif h<0:\n raise ValueError\n\n d1 = np.zeros(len(s))\n d1[1:] = (s[1:]-s[:-1]) / h\n \n return d1\n\nplt.plot(tt, d1a(fp1(tt)))"}
{"task_id": "DSP/210", "completion": "import numpy as np\nimport numbers\n\ndef d1a(s, h=1):\n \"\"\"\n Computes the 1st derivative of a 1-D numpy array using a backward difference approximation of the derivative.\n Arguments:\n s: the 1-D numpy array we will take the first derivative of.\n h: the unit step size (i.e. what the length of one step in the array represents).\n Returns:\n d1: thd 1st derivative of s.\n \"\"\"\n if not isinstance(s, np.ndarray) or not isinstance(h, numbers.Number):\n raise TypeError\n elif h<0:\n raise ValueError\n\n d1 = np.zeros(len(s))\n d1[1:] = (s[1:]-s[:-1]) / h\n \n return d1\n\nplt.plot(tt, d1a(fp1(tt)))"}
{"task_id": "DSP/211", "completion": "import numpy as np\nimport numbers\n\ndef d1b(s, h=1):\n \"\"\"\n Computes the 1st derivative of a 1-D numpy array using a centered difference approximation of the derivative.\n Arguments:\n s: the 1-D numpy array we will take the first derivative of.\n h: the unit step size (i.e. what the length of one step in the array represents).\n Returns:\n d1: thd 1st derivative of s.\n \"\"\"\n if not isinstance(s, np.ndarray) or not isinstance(h, numbers.Number):\n raise TypeError\n elif h<0:\n raise ValueError\n\n d1 = np.zeros(len(s))\n d1[1:-1] = (s[2:]-s[:-2]) / (2*h)\n \n return d1\n\nplt.plot(tt, d1b(fp1(tt), h=0.1))"}
{"task_id": "DSP/211", "completion": "import numpy as np\nimport numbers\n\ndef d1b(s, h=1):\n \"\"\"\n Computes the 1st derivative of a 1-D numpy array using a centered difference approximation of the derivative.\n Arguments:\n s: the 1-D numpy array we will take the first derivative of.\n h: the unit step size (i.e. what the length of one step in the array represents).\n Returns:\n d1: thd 1st derivative of s.\n \"\"\"\n if not isinstance(s, np.ndarray) or not isinstance(h, numbers.Number):\n raise TypeError\n elif h<0:\n raise ValueError\n\n d1 = np.zeros(len(s))\n d1[1:-1] = (s[2:]-s[:-2]) / (2*h)\n \n return d1\n\nplt.plot(tt, d1b(fp1(tt), h=0.1))"}
{"task_id": "DSP/212", "completion": "import numpy as np\nimport numbers\n\ndef d1c(s, h=1):\n \"\"\"\n Computes the 1st derivative of a 1-D numpy array using a Taylor series expansion of the 1st derivative.\n Arguments:\n s: the 1-D numpy array we will take the first derivative of.\n h: the unit step size (i.e. what the length of one step in the array represents).\n Returns:\n d1: thd 1st derivative of s.\n \"\"\"\n if not isinstance(s, np.ndarray) or not isinstance(h, numbers.Number):\n raise TypeError\n elif h<0:\n raise ValueError\n\n d1 = np.zeros(len(s))\n d1[2:-2] = ( -s[4:] + (8*s[3:-1]) - (8*s[1:-3]) + s[:-4] ) / (12*h)\n \n return d1\n\nplt.plot(tt, d1c(fp1(tt)))"}
{"task_id": "DSP/212", "completion": "import numpy as np\nimport numbers\n\ndef d1c(s, h=1):\n \"\"\"\n Computes the 1st derivative of a 1-D numpy array using a Taylor series expansion of the 1st derivative.\n Arguments:\n s: the 1-D numpy array we will take the first derivative of.\n h: the unit step size (i.e. what the length of one step in the array represents).\n Returns:\n d1: thd 1st derivative of s.\n \"\"\"\n if not isinstance(s, np.ndarray) or not isinstance(h, numbers.Number):\n raise TypeError\n elif h<0:\n raise ValueError\n\n d1 = np.zeros(len(s))\n d1[2:-2] = ( -s[4:] + (8*s[3:-1]) - (8*s[1:-3]) + s[:-4] ) / (12*h)\n \n return d1\n\nplt.plot(tt, d1c(fp1(tt)))"}
{"task_id": "DSP/213", "completion": "ts = symbols('ts')\ndef kinetics(t, A=200, b=0.46, k=0.35):\n # YOUR CODE HERE\n \"\"\"\n Represents a pharmokinetic model of drug absorption and clearance.\n \n Arguments:\n t: time\n A: constant\n b: clearance rate for the digestive system with b > k typically.\n k: time constant representing how the drug is cleared from body (e.g. through urine)\n \n Returns: the max dose time\n \"\"\"\n return (A*b/(b-k))*( (exp(-k*t)) - (exp(-b*t)) )"}
{"task_id": "DSP/213", "completion": "ts = symbols('ts')\ndef kinetics(t, A=200, b=0.46, k=0.35):\n # YOUR CODE HERE\n \"\"\"\n Represents a pharmokinetic model of drug absorption and clearance.\n \n Arguments:\n t: time\n A: constant\n b: clearance rate for the digestive system with b > k typically.\n k: time constant representing how the drug is cleared from body (e.g. through urine)\n \n Returns: the max dose time\n \"\"\"\n return (A*b/(b-k))*( (exp(-k*t)) - (exp(-b*t)) )"}
{"task_id": "DSP/214", "completion": "sequences = {\"seq1\": sequence1, \"seq2\": sequence2, \"seq3\": sequence3}"}
{"task_id": "DSP/214", "completion": "sequences = {\"seq1\": sequence1, \"seq2\": sequence2, \"seq3\": sequence3}"}
{"task_id": "DSP/215", "completion": "sequences = {\"seq1\":sequence1, \"seq2\":sequence2, \"seq3\":sequence3}\n# YOUR CODE HERE\ndef count_kmers(sequences, kmers):\n rslts = {} #rslts = {seq1:{kmer1:freq, kmer2:freq, kmer3 freq}, seq2:{kmer1:freq, kmer2:freq}}\n if kmers == None:\n kmers = ('A')\n for seq in sequences:\n sequence = sequences[seq]\n \"\".join(sequence.split())\n entry = {}\n for kmer in kmers:\n entry[kmer] = 0\n l = len(kmer)\n for i in range(0, len(sequence)):\n test = sequence[i:i+l]\n if len(test) != l:\n break\n if test == kmer:\n entry[kmer] += 1\n \n rslts[seq] = entry\n \n print(rslts)\n return rslts\n#raise NotImplementedError()"}
{"task_id": "DSP/215", "completion": "sequences = {\"seq1\":sequence1, \"seq2\":sequence2, \"seq3\":sequence3}\n# YOUR CODE HERE\ndef count_kmers(sequences, kmers):\n rslts = {} #rslts = {seq1:{kmer1:freq, kmer2:freq, kmer3 freq}, seq2:{kmer1:freq, kmer2:freq}}\n if kmers == None:\n kmers = ('A')\n for seq in sequences:\n sequence = sequences[seq]\n \"\".join(sequence.split())\n entry = {}\n for kmer in kmers:\n entry[kmer] = 0\n l = len(kmer)\n for i in range(0, len(sequence)):\n test = sequence[i:i+l]\n if len(test) != l:\n break\n if test == kmer:\n entry[kmer] += 1\n \n rslts[seq] = entry\n \n print(rslts)\n return rslts\n#raise NotImplementedError()"}
{"task_id": "DSP/216", "completion": "def validate_alpha(alpha):\n # YOUR CODE HERE\n alpha = float(alpha)\n if alpha > 0 and alpha < 1:\n return alpha\n else:\n raise ValueError"}
{"task_id": "DSP/216", "completion": "def validate_alpha(alpha):\n # YOUR CODE HERE\n alpha = float(alpha)\n if alpha > 0 and alpha < 1:\n return alpha\n else:\n raise ValueError"}
{"task_id": "DSP/217", "completion": "def validate_color(color): \n # YOUR CODE HERE\n color = int(color)\n if color >= 0 and color <= 255:\n return color\n else:\n raise ValueError"}
{"task_id": "DSP/217", "completion": "def validate_color(color): \n # YOUR CODE HERE\n color = int(color)\n if color >= 0 and color <= 255:\n return color\n else:\n raise ValueError"}
{"task_id": "DSP/218", "completion": "from collections import namedtuple\nimport math\nrgbalpha = namedtuple(\"rgbalpha\",['r','g','b','alpha'])\nclass rgba(rgbalpha):\n def __new__(cls, *args, **kwargs):\n return super().__new__(cls, validate_color(args[0]),\n validate_color(args[1]),\n validate_color(args[2]),\n validate_alpha(args[3]))\n def __init__(self, *args, name=\"null\"):\n # YOUR CODE HERE\n self.r = args[0]\n self.g = args[1]\n self.b = args[2]\n self.alpha = args[3]\n \n @property\n # YOUR CODE HERE\n def alpha(self):\n return self.__alpha\n @alpha.setter\n # YOUR CODE HERE\n def alpha(self,alpha):\n self.__alpha = alpha\n \n @property\n # YOUR CODE HERE\n def r(self):\n return self.__r\n @r.setter\n # YOUR CODE HERE\n def r(self,r):\n self.__r = int(r)\n \n @property\n # YOUR CODE HERE\n def g(self):\n return self.__g\n @g.setter\n # YOUR CODE HERE\n def g(self,g):\n self.__g = int(g)\n \n @property\n # YOUR CODE HERE\n def b(self):\n return self.__b\n @b.setter\n # YOUR CODE HERE\n def b(self,b):\n self.__b = int(b)\n \n \n def invert_rgb(self): \n \"\"\"\n this function inverts the RGB color by subtracting \n all color values from 255 and returns a new rgba object with the \n new color values.\n \n alpha is not modified\n \n name\n \"\"\"\n # YOUR CODE HERE\n self.r = 255 - self.r\n self.g = 255 - self.g\n self.b = 255 - self.b\n return self\n \n def grayscale(self): \n \"\"\"\n this function converts RGB color to grayscale by using a \n weight average formula: 0.299Red+0.587Green+0.114Blue\n \"\"\"\n # YOUR CODE HERE\n gray = int((self.r * 0.299) + (self.g * 0.587) + (self.b * 0.114))\n self.r = gray\n self.g = gray\n self.b = gray\n return self\n \n def __str__(self):\n # YOUR CODE HERE\n alphas = str(self.alpha)\n rs = str(self.r).zfill(3)\n gs = str(self.g).zfill(3)\n bs = str(self.b).zfill(3)\n return rs + \" \" + gs + \" \" + bs + \" \" + alphas\n \n def __repr__(self):\n # YOUR CODE HERE\n return str(type(self)) + self.__str__()\n \n \n def __add__(self,color):\n # YOUR CODE HERE\n \"\"\"\n When adding two rgba instances (e.g. c1 and c2) to create a new rgba instance (e.g. c3), the color channels of c3 should be the sum of the two values mod 256. For example, c3=(c1.r+c2.r)mod256 .\n The alpha value should be the maximum of the two alpha values ( c3.alpha=max(c1.alpha,c2.alpha) )\n \"\"\"\n r_new = (self.r + color.r) % 256\n g_new = (self.g + color.g) % 256\n b_new = (self.b + color.b) % 256\n alpha_new = max(self.alpha, color.alpha)\n \n return rgba(r_new, g_new, b_new, alpha_new)\n \n def __eq__(self,color):\n # YOUR CODE HERE\n if self.r == color.r and self.g == color.g and self.b == color.b:\n return True\n else:\n return False\n \n def __abs__(self):\n # YOUR CODE HERE\n return math.sqrt( (self.r**2) + (self.g**2) + (self.b**2) )"}
{"task_id": "DSP/218", "completion": "from collections import namedtuple\nimport math\nrgbalpha = namedtuple(\"rgbalpha\",['r','g','b','alpha'])\nclass rgba(rgbalpha):\n def __new__(cls, *args, **kwargs):\n return super().__new__(cls, validate_color(args[0]),\n validate_color(args[1]),\n validate_color(args[2]),\n validate_alpha(args[3]))\n def __init__(self, *args, name=\"null\"):\n # YOUR CODE HERE\n self.r = args[0]\n self.g = args[1]\n self.b = args[2]\n self.alpha = args[3]\n \n @property\n # YOUR CODE HERE\n def alpha(self):\n return self.__alpha\n @alpha.setter\n # YOUR CODE HERE\n def alpha(self,alpha):\n self.__alpha = alpha\n \n @property\n # YOUR CODE HERE\n def r(self):\n return self.__r\n @r.setter\n # YOUR CODE HERE\n def r(self,r):\n self.__r = int(r)\n \n @property\n # YOUR CODE HERE\n def g(self):\n return self.__g\n @g.setter\n # YOUR CODE HERE\n def g(self,g):\n self.__g = int(g)\n \n @property\n # YOUR CODE HERE\n def b(self):\n return self.__b\n @b.setter\n # YOUR CODE HERE\n def b(self,b):\n self.__b = int(b)\n \n \n def invert_rgb(self): \n \"\"\"\n this function inverts the RGB color by subtracting \n all color values from 255 and returns a new rgba object with the \n new color values.\n \n alpha is not modified\n \n name\n \"\"\"\n # YOUR CODE HERE\n self.r = 255 - self.r\n self.g = 255 - self.g\n self.b = 255 - self.b\n return self\n \n def grayscale(self): \n \"\"\"\n this function converts RGB color to grayscale by using a \n weight average formula: 0.299Red+0.587Green+0.114Blue\n \"\"\"\n # YOUR CODE HERE\n gray = int((self.r * 0.299) + (self.g * 0.587) + (self.b * 0.114))\n self.r = gray\n self.g = gray\n self.b = gray\n return self\n \n def __str__(self):\n # YOUR CODE HERE\n alphas = str(self.alpha)\n rs = str(self.r).zfill(3)\n gs = str(self.g).zfill(3)\n bs = str(self.b).zfill(3)\n return rs + \" \" + gs + \" \" + bs + \" \" + alphas\n \n def __repr__(self):\n # YOUR CODE HERE\n return str(type(self)) + self.__str__()\n \n \n def __add__(self,color):\n # YOUR CODE HERE\n \"\"\"\n When adding two rgba instances (e.g. c1 and c2) to create a new rgba instance (e.g. c3), the color channels of c3 should be the sum of the two values mod 256. For example, c3=(c1.r+c2.r)mod256 .\n The alpha value should be the maximum of the two alpha values ( c3.alpha=max(c1.alpha,c2.alpha) )\n \"\"\"\n r_new = (self.r + color.r) % 256\n g_new = (self.g + color.g) % 256\n b_new = (self.b + color.b) % 256\n alpha_new = max(self.alpha, color.alpha)\n \n return rgba(r_new, g_new, b_new, alpha_new)\n \n def __eq__(self,color):\n # YOUR CODE HERE\n if self.r == color.r and self.g == color.g and self.b == color.b:\n return True\n else:\n return False\n \n def __abs__(self):\n # YOUR CODE HERE\n return math.sqrt( (self.r**2) + (self.g**2) + (self.b**2) )"}
{"task_id": "DSP/219", "completion": "from math import *\n\ndef bmi(h, w):\n # YOUR CODE HERE\n bmis = []\n for x in range(0,len(h)):\n bmis.append(w[x] / (h[x]*2.54/100.0)**2)\n \n bmis = np.array(bmis)\n \n return bmis\n raise NotImplementedError()"}
{"task_id": "DSP/219", "completion": "from math import *\n\ndef bmi(h, w):\n # YOUR CODE HERE\n bmis = []\n for x in range(0,len(h)):\n bmis.append(w[x] / (h[x]*2.54/100.0)**2)\n \n bmis = np.array(bmis)\n \n return bmis\n raise NotImplementedError()"}
{"task_id": "DSP/220", "completion": "import math\n\ndef find_roots(a=1,b=1,c=1):\n \"\"\"\n This is a docstring. It is what the help() function returns\n about this function.\n \"\"\"\n # YOUR CODE HERE\n x = b**2-4*a*c\n \n r1 = (-b - math.sqrt(x))/(2*a)\n r2 = (-b + math.sqrt(x)) /(2*a)\n \n return r1, r2\n \n raise NotImplementedError()"}
{"task_id": "DSP/220", "completion": "import math\n\ndef find_roots(a=1,b=1,c=1):\n \"\"\"\n This is a docstring. It is what the help() function returns\n about this function.\n \"\"\"\n # YOUR CODE HERE\n x = b**2-4*a*c\n \n r1 = (-b - math.sqrt(x))/(2*a)\n r2 = (-b + math.sqrt(x)) /(2*a)\n \n return r1, r2\n \n raise NotImplementedError()"}
{"task_id": "DSP/221", "completion": "def age_string(age):\n decade = None\n # YOUR CODE HERE\n age = str(age)\n if len(age) == 1:\n decade = 0\n else:\n decade = str(age)[0] + \"0\"\n \n return \"Age in %ds\"%int(decade)\n raise NotImplementedError()"}
{"task_id": "DSP/221", "completion": "def age_string(age):\n decade = None\n # YOUR CODE HERE\n age = str(age)\n if len(age) == 1:\n decade = 0\n else:\n decade = str(age)[0] + \"0\"\n \n return \"Age in %ds\"%int(decade)\n raise NotImplementedError()"}
{"task_id": "DSP/222", "completion": "def hounsfield(I, I0, L):\n # YOUR CODE HERE\n mu = -math.log(I / I0) / L\n print (mu)\n muwater = 0.1928\n muair = 0.0002\n \n #hu = 1000 * ((mu - muwater) / (muwater - muair))\n \n return mu\n raise NotImplementedError()"}
{"task_id": "DSP/222", "completion": "def hounsfield(I, I0, L):\n # YOUR CODE HERE\n mu = -math.log(I / I0) / L\n print (mu)\n muwater = 0.1928\n muair = 0.0002\n \n #hu = 1000 * ((mu - muwater) / (muwater - muair))\n \n return mu\n raise NotImplementedError()"}
{"task_id": "DSP/223", "completion": "income_data = pd.read_csv(\"https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data\", header = None, skipinitialspace= True)\n# Giving meaningful column names, as per the `auto_mpg.names` file\nincome_data = income_data.rename(columns={0: \"age\",1: \"workclass\", 2: \"fnlwgt\", 3: \"education\", 4: \"education_num\", 5: \"marital_status\", 6: \"occupation\", 7: \"relationship\", 8: \"race\", 9: \"sex\", 10: \"capital_gain\", 11: \"capital_loss\", 12: \"hours_per_week\", 13:\"native_country\", 14: \"income\"})\n#income_data['income'] = income_data['income'].map({' <=50K': 0, ' >50K': 1}).astype(int) #convert type to int"}
{"task_id": "DSP/223", "completion": "income_data = pd.read_csv(\"https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data\", header = None, skipinitialspace= True)\n# Giving meaningful column names, as per the `auto_mpg.names` file\nincome_data = income_data.rename(columns={0: \"age\",1: \"workclass\", 2: \"fnlwgt\", 3: \"education\", 4: \"education_num\", 5: \"marital_status\", 6: \"occupation\", 7: \"relationship\", 8: \"race\", 9: \"sex\", 10: \"capital_gain\", 11: \"capital_loss\", 12: \"hours_per_week\", 13:\"native_country\", 14: \"income\"})\n#income_data['income'] = income_data['income'].map({' <=50K': 0, ' >50K': 1}).astype(int) #convert type to int"}
{"task_id": "DSP/224", "completion": "def get_num_people_with_higher_gain(dataframe, threshold_gain):\n highpayed = len(dataframe[dataframe.capital_gain >= threshold_gain]) # put the threshold_gain\n return highpayed\nhighpayed = get_num_people_with_higher_gain(income_data, 60000)\nprint(highpayed)"}
{"task_id": "DSP/224", "completion": "def get_num_people_with_higher_gain(dataframe, threshold_gain):\n highpayed = len(dataframe[dataframe.capital_gain >= threshold_gain]) # put the threshold_gain\n return highpayed\nhighpayed = get_num_people_with_higher_gain(income_data, 60000)\nprint(highpayed)"}
{"task_id": "DSP/225", "completion": "def most_prominent_marital_status(dataframe):\n status = dataframe['marital_status'].value_counts().sort_index().sort_values(ascending=False).index[0] # get the first row of sorted values for marital status\n num_people = dataframe['marital_status'].value_counts().sort_index().sort_values(ascending=False).values[0] # get the first row value of sorted values for marital status\n return status, num_people\nprint(most_prominent_marital_status(income_data))"}
{"task_id": "DSP/225", "completion": "def most_prominent_marital_status(dataframe):\n status = dataframe['marital_status'].value_counts().sort_index().sort_values(ascending=False).index[0] # get the first row of sorted values for marital status\n num_people = dataframe['marital_status'].value_counts().sort_index().sort_values(ascending=False).values[0] # get the first row value of sorted values for marital status\n return status, num_people\nprint(most_prominent_marital_status(income_data))"}
{"task_id": "DSP/226", "completion": "def get_num_people_by_age_category(dataframe):\n #young, middle_aged, old = (len(dataframe[ dataframe.age <=30]), len(dataframe[(dataframe.age >30) & (dataframe.age <=60)]), len(dataframe[ dataframe.age >60]))\n young = dataframe['age'][dataframe['age'] <= 30].count()\n middle_aged = dataframe['age'][(dataframe.age > 30) & (dataframe.age <= 60)].count()\n #middle_aged = dataframe['age'][(dataframe.age <= 60)].count()\n old = dataframe['age'][dataframe['age'] > 60].count()\n return young, middle_aged, old\nprint(get_num_people_by_age_category(income_data))"}
{"task_id": "DSP/226", "completion": "def get_num_people_by_age_category(dataframe):\n #young, middle_aged, old = (len(dataframe[ dataframe.age <=30]), len(dataframe[(dataframe.age >30) & (dataframe.age <=60)]), len(dataframe[ dataframe.age >60]))\n young = dataframe['age'][dataframe['age'] <= 30].count()\n middle_aged = dataframe['age'][(dataframe.age > 30) & (dataframe.age <= 60)].count()\n #middle_aged = dataframe['age'][(dataframe.age <= 60)].count()\n old = dataframe['age'][dataframe['age'] > 60].count()\n return young, middle_aged, old\nprint(get_num_people_by_age_category(income_data))"}
{"task_id": "DSP/227", "completion": "def get_second_highest_num_people(dataframe):\n num_people = dataframe['native_country'].value_counts().sort_index().sort_values(ascending=False).values[1]# get the second row of sorted values for marital status\n country = dataframe['native_country'].value_counts().sort_index().sort_values(ascending=False).index[1] # get the second row value of sorted values for marital status\n return num_people, country\nprint(get_second_highest_num_people(income_data))"}
{"task_id": "DSP/227", "completion": "def get_second_highest_num_people(dataframe):\n num_people = dataframe['native_country'].value_counts().sort_index().sort_values(ascending=False).values[1]# get the second row of sorted values for marital status\n country = dataframe['native_country'].value_counts().sort_index().sort_values(ascending=False).index[1] # get the second row value of sorted values for marital status\n return num_people, country\nprint(get_second_highest_num_people(income_data))"}
{"task_id": "DSP/228", "completion": "def get_mean_working_hours_by_income(dataframe):\n hours = dataframe.groupby(['occupation'])['hours_per_week'].mean().sort_values(ascending=False) # calculate average values for each occupation\n return hours\nprint(get_mean_working_hours_by_income(income_data))"}
{"task_id": "DSP/228", "completion": "def get_mean_working_hours_by_income(dataframe):\n hours = dataframe.groupby(['occupation'])['hours_per_week'].mean().sort_values(ascending=False) # calculate average values for each occupation\n return hours\nprint(get_mean_working_hours_by_income(income_data))"}
{"task_id": "DSP/229", "completion": "mpg_data = pd.read_fwf(\"http://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data\",header = None, \nnames=[\"mpg\",\"cylinders\",\"displacement\",\"horsepower\",\"weight\",\"acceleration\",\"model_year\",\"origin\",\"car_name\"],na_values = [\"?\"])\n\n# YOUR CODE HERE\n#raise NotImplementedError()"}
{"task_id": "DSP/229", "completion": "mpg_data = pd.read_fwf(\"http://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data\",header = None, \nnames=[\"mpg\",\"cylinders\",\"displacement\",\"horsepower\",\"weight\",\"acceleration\",\"model_year\",\"origin\",\"car_name\"],na_values = [\"?\"])\n\n# YOUR CODE HERE\n#raise NotImplementedError()"}
{"task_id": "DSP/230", "completion": "mpg_data['horsepower'] = mpg_data['horsepower'].apply(pd.to_numeric, errors='coerce' )\n#raise NotImplementedError()"}
{"task_id": "DSP/230", "completion": "mpg_data['horsepower'] = mpg_data['horsepower'].apply(pd.to_numeric, errors='coerce' )\n#raise NotImplementedError()"}
{"task_id": "DSP/231", "completion": "mpg_data =mpg_data[pd.notnull(mpg_data['horsepower'])]\n#raise NotImplementedError()"}
{"task_id": "DSP/231", "completion": "mpg_data =mpg_data[pd.notnull(mpg_data['horsepower'])]\n#raise NotImplementedError()"}
{"task_id": "DSP/232", "completion": "def get_model_names_smallest_cylinders(dataframe):\n \"\"\"\n Returns the names of the cars with the smallest number of cylinders\n \"\"\"\n selection = dataframe.cylinders.min()\n car_names = dataframe.loc[dataframe['cylinders'] == selection].car_name\n # YOUR CODE HERE\n # raise NotImplementedError()\n return car_names"}
{"task_id": "DSP/232", "completion": "def get_model_names_smallest_cylinders(dataframe):\n \"\"\"\n Returns the names of the cars with the smallest number of cylinders\n \"\"\"\n selection = dataframe.cylinders.min()\n car_names = dataframe.loc[dataframe['cylinders'] == selection].car_name\n # YOUR CODE HERE\n # raise NotImplementedError()\n return car_names"}
{"task_id": "DSP/233", "completion": "def calculate_correlation(dataframe, first_column, second_column):\n \"\"\"\n Calculates and returns the correlation coefficient between the two columns in the dataframe.\n \"\"\"\n correlation = dataframe[first_column].corr(dataframe[second_column])\n # YOUR CODE HERE\n #raise NotImplementedError()\n return correlation"}
{"task_id": "DSP/233", "completion": "def calculate_correlation(dataframe, first_column, second_column):\n \"\"\"\n Calculates and returns the correlation coefficient between the two columns in the dataframe.\n \"\"\"\n correlation = dataframe[first_column].corr(dataframe[second_column])\n # YOUR CODE HERE\n #raise NotImplementedError()\n return correlation"}
{"task_id": "DSP/234", "completion": "income_data = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data',header=None,\n na_values=[\"?\"],\n names=[\"age\",\"working_class\",\"fmlgtw\",\"education\",\"education_num\",\"marital_status\",\"occupation\",\"relationship\"\n ,\"race\",\"sex\",\"capital_gain\",\"capital_loss\",\"hours_per_week\",\"native_country\",\"total_income\"]\n , skipinitialspace= True)\n# YOUR CODE HERE\n#raise NotImplementedError()"}
{"task_id": "DSP/234", "completion": "income_data = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data',header=None,\n na_values=[\"?\"],\n names=[\"age\",\"working_class\",\"fmlgtw\",\"education\",\"education_num\",\"marital_status\",\"occupation\",\"relationship\"\n ,\"race\",\"sex\",\"capital_gain\",\"capital_loss\",\"hours_per_week\",\"native_country\",\"total_income\"]\n , skipinitialspace= True)\n# YOUR CODE HERE\n#raise NotImplementedError()"}
{"task_id": "DSP/235", "completion": "def get_num_people_with_higher_gain(dataframe, threshold_gain):\n # YOUR CODE HERE\n return len(dataframe[ dataframe.capital_gain >=threshold_gain])\n #raise NotImplementedError()"}
{"task_id": "DSP/235", "completion": "def get_num_people_with_higher_gain(dataframe, threshold_gain):\n # YOUR CODE HERE\n return len(dataframe[ dataframe.capital_gain >=threshold_gain])\n #raise NotImplementedError()"}
{"task_id": "DSP/236", "completion": "def most_prominent_marital_status(dataframe):\n #status = \"\"\n #num_people = 0\n values = dataframe['marital_status'].value_counts().sort_values(ascending=False)\n\n status =values.index[0]\n num_people =values[0]\n # YOUR CODE HERE\n #raise NotImplementedError()\n return (status, num_people)"}
{"task_id": "DSP/236", "completion": "def most_prominent_marital_status(dataframe):\n #status = \"\"\n #num_people = 0\n values = dataframe['marital_status'].value_counts().sort_values(ascending=False)\n\n status =values.index[0]\n num_people =values[0]\n # YOUR CODE HERE\n #raise NotImplementedError()\n return (status, num_people)"}
{"task_id": "DSP/237", "completion": "def get_num_people_by_age_category(dataframe):\n #young, middle_aged, old = (0, 0, 0)\n young, middle_aged, old = (len(dataframe[ dataframe.age <=30])\n , len(dataframe[(dataframe.age >30) & (dataframe.age <=60)]),\n len(dataframe[dataframe.age >60]))\n # YOUR CODE HERE\n #raise NotImplementedError()\n return young, middle_aged, old"}
{"task_id": "DSP/237", "completion": "def get_num_people_by_age_category(dataframe):\n #young, middle_aged, old = (0, 0, 0)\n young, middle_aged, old = (len(dataframe[ dataframe.age <=30])\n , len(dataframe[(dataframe.age >30) & (dataframe.age <=60)]),\n len(dataframe[dataframe.age >60]))\n # YOUR CODE HERE\n #raise NotImplementedError()\n return young, middle_aged, old"}
{"task_id": "DSP/238", "completion": "def get_second_highest_num_people(dataframe):\n #num_people, country = 0, \"\"\n # YOUR CODE HERE\n countries=dataframe['native_country'].value_counts().sort_values(ascending=False)\n num_people,country = countries[1],countries.index[1]\n #raise NotImplementedError()\n return num_people, country"}
{"task_id": "DSP/238", "completion": "def get_second_highest_num_people(dataframe):\n #num_people, country = 0, \"\"\n # YOUR CODE HERE\n countries=dataframe['native_country'].value_counts().sort_values(ascending=False)\n num_people,country = countries[1],countries.index[1]\n #raise NotImplementedError()\n return num_people, country"}
{"task_id": "DSP/239", "completion": "def get_mean_working_hours_by_income(dataframe):\n hours = dataframe.groupby(['occupation'])['hours_per_week'].mean().sort_values(ascending=False)\n return hours\n #raise NotImplementedError()"}
{"task_id": "DSP/239", "completion": "def get_mean_working_hours_by_income(dataframe):\n hours = dataframe.groupby(['occupation'])['hours_per_week'].mean().sort_values(ascending=False)\n return hours\n #raise NotImplementedError()"}
{"task_id": "DSP/240", "completion": "income_data =pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data',header=None,na_values=[\"?\"],\n names=[\"age\",\"working_class\",\"fmlgtw\",\"education\",\"education_num\",\"marital_status\",\"occupation\",\"relationship\"\n ,\"race\",\"sex\",\"capital_gain\",\"capital_loss\",\"hours_per_week\",\"native_country\",\"total_income\"]\n ,sep=\", \")\n# YOUR CODE HERE\n#raise NotImplementedError()"}
{"task_id": "DSP/240", "completion": "income_data =pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data',header=None,na_values=[\"?\"],\n names=[\"age\",\"working_class\",\"fmlgtw\",\"education\",\"education_num\",\"marital_status\",\"occupation\",\"relationship\"\n ,\"race\",\"sex\",\"capital_gain\",\"capital_loss\",\"hours_per_week\",\"native_country\",\"total_income\"]\n ,sep=\", \")\n# YOUR CODE HERE\n#raise NotImplementedError()"}
{"task_id": "DSP/241", "completion": "def get_num_people_with_higher_gain(dataframe, threshold_gain):\n \n return len(dataframe[ dataframe.capital_gain >=threshold_gain])\n # raise NotImplementedError()"}
{"task_id": "DSP/241", "completion": "def get_num_people_with_higher_gain(dataframe, threshold_gain):\n \n return len(dataframe[ dataframe.capital_gain >=threshold_gain])\n # raise NotImplementedError()"}
{"task_id": "DSP/242", "completion": "def most_prominent_marital_status(dataframe):\n \n values = income_data['marital_status'].value_counts().sort_index().sort_values(ascending=False)\n\n status =values.index[0]\n num_people =values[0]\n # YOUR CODE HERE\n #raise NotImplementedError()\n return (status, num_people)"}
{"task_id": "DSP/242", "completion": "def most_prominent_marital_status(dataframe):\n \n values = income_data['marital_status'].value_counts().sort_index().sort_values(ascending=False)\n\n status =values.index[0]\n num_people =values[0]\n # YOUR CODE HERE\n #raise NotImplementedError()\n return (status, num_people)"}
{"task_id": "DSP/243", "completion": "def get_num_people_by_age_category(dataframe):\n #young, middle_aged, old = (0, 0, 0)\n # YOUR CODE HERE\n young, middle_aged, old = (len(dataframe[ dataframe.age <=30])\n , len(dataframe[(dataframe.age >30) & (dataframe.age <=60)]),\n len(dataframe[dataframe.age >60]))\n #raise NotImplementedError()\n return young, middle_aged, old"}
{"task_id": "DSP/243", "completion": "def get_num_people_by_age_category(dataframe):\n #young, middle_aged, old = (0, 0, 0)\n # YOUR CODE HERE\n young, middle_aged, old = (len(dataframe[ dataframe.age <=30])\n , len(dataframe[(dataframe.age >30) & (dataframe.age <=60)]),\n len(dataframe[dataframe.age >60]))\n #raise NotImplementedError()\n return young, middle_aged, old"}
{"task_id": "DSP/244", "completion": "def get_second_highest_num_people(dataframe):\n countries=dataframe['native_country'].value_counts().sort_values(ascending=False)\n num_people, country = countries[1],countries.index[1]\n # YOUR CODE HERE\n #raise NotImplementedError()\n return num_people, country"}
{"task_id": "DSP/244", "completion": "def get_second_highest_num_people(dataframe):\n countries=dataframe['native_country'].value_counts().sort_values(ascending=False)\n num_people, country = countries[1],countries.index[1]\n # YOUR CODE HERE\n #raise NotImplementedError()\n return num_people, country"}
{"task_id": "DSP/245", "completion": "def get_mean_working_hours_by_income(dataframe):\n # YOUR CODE HERE\n return dataframe.groupby(['occupation'])['hours_per_week'].mean().sort_values( ascending=False)\n #raise NotImplementedError()"}
{"task_id": "DSP/245", "completion": "def get_mean_working_hours_by_income(dataframe):\n # YOUR CODE HERE\n return dataframe.groupby(['occupation'])['hours_per_week'].mean().sort_values( ascending=False)\n #raise NotImplementedError()"}
{"task_id": "DSP/246", "completion": "sequences = {\"seq1\": sequence1, \"seq2\": sequence2, \"seq3\": sequence3}"}
{"task_id": "DSP/246", "completion": "sequences = {\"seq1\": sequence1, \"seq2\": sequence2, \"seq3\": sequence3}"}
{"task_id": "DSP/247", "completion": "def bootstrap(x, y):\n \"\"\"Return boostrapped versions of the input X and Y arrays, perserving correlations.\n \n Parameters\n ----------\n x: ndarray\n Input x array.\n y: ndarray\n Input y array.\n \n Returns\n -------\n xx: ndarray\n The boostrapped x array with the same shape as x and correlated random samples\n drawn with replacement.\n yy: ndarray\n The bootstrapped y array with the same shape as y and correlated random samples\n drawn with replacement.\n \"\"\"\n idx = np.random.choice(x.size, size=x.size, replace=True)\n return x[idx], y[idx]"}
{"task_id": "DSP/247", "completion": "def bootstrap(x, y):\n \"\"\"Return boostrapped versions of the input X and Y arrays, perserving correlations.\n \n Parameters\n ----------\n x: ndarray\n Input x array.\n y: ndarray\n Input y array.\n \n Returns\n -------\n xx: ndarray\n The boostrapped x array with the same shape as x and correlated random samples\n drawn with replacement.\n yy: ndarray\n The bootstrapped y array with the same shape as y and correlated random samples\n drawn with replacement.\n \"\"\"\n idx = np.random.choice(x.size, size=x.size, replace=True)\n return x[idx], y[idx]"}
{"task_id": "DSP/248", "completion": "s4 = df1.iloc[::2, -1]"}
{"task_id": "DSP/248", "completion": "s4 = df1.iloc[::2, -1]"}
{"task_id": "DSP/249", "completion": "numeric_features = ['pclass', 'age', 'sibsp', 'parch', 'fare', 'alone', 'child']\nX = raw_data.loc[:, numeric_features]"}
{"task_id": "DSP/249", "completion": "numeric_features = ['pclass', 'age', 'sibsp', 'parch', 'fare', 'alone', 'child']\nX = raw_data.loc[:, numeric_features]"}
{"task_id": "DSP/250", "completion": "y = raw_data.survived"}
{"task_id": "DSP/250", "completion": "y = raw_data.survived"}
{"task_id": "DSP/251", "completion": "from sklearn.model_selection import train_test_split\n\nXtrain, Xtest, ytrain, ytest = train_test_split(X, y, train_size=0.70, random_state=0)"}
{"task_id": "DSP/251", "completion": "from sklearn.model_selection import train_test_split\n\nXtrain, Xtest, ytrain, ytest = train_test_split(X, y, train_size=0.70, random_state=0)"}
{"task_id": "DSP/252", "completion": "data = np.genfromtxt('data/open_exoplanet_catalogue.txt', delimiter=',', dtype=np.float64)"}
{"task_id": "DSP/252", "completion": "data = np.genfromtxt('data/open_exoplanet_catalogue.txt', delimiter=',', dtype=np.float64)"}
{"task_id": "DSP/253", "completion": "def same_digits(x, y):\n \"\"\"Do the integers x and y have the same digits, regardless of order.\"\"\"\n return sorted(x) == sorted(y)"}
{"task_id": "DSP/253", "completion": "def same_digits(x, y):\n \"\"\"Do the integers x and y have the same digits, regardless of order.\"\"\"\n return sorted(x) == sorted(y)"}
{"task_id": "DSP/254", "completion": "g1 = titanic.groupby(['sex']).aggregate({'age': pd.DataFrame.mean})"}
{"task_id": "DSP/254", "completion": "g1 = titanic.groupby(['sex']).aggregate({'age': pd.DataFrame.mean})"}
{"task_id": "DSP/255", "completion": "(t, W) = wiener(1.0, 1000)\nprint(len(t), len(W))"}
{"task_id": "DSP/255", "completion": "(t, W) = wiener(1.0, 1000)\nprint(len(t), len(W))"}
{"task_id": "DSP/256", "completion": "def find_peaks(a):\n \"\"\"Find the indices of the local maxima in a sequence.\"\"\"\n a_diff = np.full(len(a), np.inf)\n a_rev_diff = np.full(len(a), np.inf)\n \n for index in range(len(a) - 1):\n a_diff[index] = a[index] - a[index + 1]\n a_rev_diff[index + 1] = a[index + 1] - a[index]\n\n indices = np.where(np.logical_and(a_diff > 0, a_rev_diff > 0))[0]\n return indices"}
{"task_id": "DSP/256", "completion": "def find_peaks(a):\n \"\"\"Find the indices of the local maxima in a sequence.\"\"\"\n a_diff = np.full(len(a), np.inf)\n a_rev_diff = np.full(len(a), np.inf)\n \n for index in range(len(a) - 1):\n a_diff[index] = a[index] - a[index + 1]\n a_rev_diff[index + 1] = a[index + 1] - a[index]\n\n indices = np.where(np.logical_and(a_diff > 0, a_rev_diff > 0))[0]\n return indices"}
{"task_id": "DSP/257", "completion": "def vector_sum(x, y):\n \"\"\"Compute the vector sum of x and y as a Python list.\"\"\"\n assert len(x) == len(y)\n return [pair[0] + pair[1] for pair in zip(x, y)]"}
{"task_id": "DSP/257", "completion": "def vector_sum(x, y):\n \"\"\"Compute the vector sum of x and y as a Python list.\"\"\"\n assert len(x) == len(y)\n return [pair[0] + pair[1] for pair in zip(x, y)]"}
{"task_id": "DSP/258", "completion": "def vector_diff(x, y):\n \"\"\"Compute the vector difference of x and y as a Python list.\"\"\"\n assert len(x) == len(y)\n return [pair[0] - pair[1] for pair in zip(x, y)]"}
{"task_id": "DSP/258", "completion": "def vector_diff(x, y):\n \"\"\"Compute the vector difference of x and y as a Python list.\"\"\"\n assert len(x) == len(y)\n return [pair[0] - pair[1] for pair in zip(x, y)]"}
{"task_id": "DSP/259", "completion": "def vector_scalar_mul(a, x):\n \"\"\"Compute a*x as a Python list.\"\"\"\n return [a * elem for elem in x]"}
{"task_id": "DSP/259", "completion": "def vector_scalar_mul(a, x):\n \"\"\"Compute a*x as a Python list.\"\"\"\n return [a * elem for elem in x]"}
{"task_id": "DSP/260", "completion": "def vector_dot(x, y):\n \"\"\"Compute the dot product of vectors a and b.\"\"\"\n assert len(x) == len(y)\n return sum([pair[0] * pair[1] for pair in zip(x, y)])"}
{"task_id": "DSP/260", "completion": "def vector_dot(x, y):\n \"\"\"Compute the dot product of vectors a and b.\"\"\"\n assert len(x) == len(y)\n return sum([pair[0] * pair[1] for pair in zip(x, y)])"}
{"task_id": "DSP/261", "completion": "def L1(x):\n \"\"\"Compute the L1 norm of x.\"\"\"\n return sum([abs(elem) for elem in x])"}
{"task_id": "DSP/261", "completion": "def L1(x):\n \"\"\"Compute the L1 norm of x.\"\"\"\n return sum([abs(elem) for elem in x])"}
{"task_id": "DSP/262", "completion": "def L2(x):\n \"\"\"Compute the L2 norm of x.\"\"\"\n return math.sqrt(sum([elem ** 2 for elem in x]))"}
{"task_id": "DSP/262", "completion": "def L2(x):\n \"\"\"Compute the L2 norm of x.\"\"\"\n return math.sqrt(sum([elem ** 2 for elem in x]))"}
{"task_id": "DSP/263", "completion": "def mse(x, y):\n \"\"\"Compute the mean squared error between x and y.\"\"\"\n assert len(x) == len(y)\n return sum([elem ** 2 for elem in vector_diff(x, y)]) / len(x)"}
{"task_id": "DSP/263", "completion": "def mse(x, y):\n \"\"\"Compute the mean squared error between x and y.\"\"\"\n assert len(x) == len(y)\n return sum([elem ** 2 for elem in vector_diff(x, y)]) / len(x)"}
{"task_id": "DSP/264", "completion": "def mean(x):\n \"\"\"Compute the mean of the elements of x.\"\"\"\n return sum(x) / len(x)"}
{"task_id": "DSP/264", "completion": "def mean(x):\n \"\"\"Compute the mean of the elements of x.\"\"\"\n return sum(x) / len(x)"}
{"task_id": "DSP/265", "completion": "def var(x):\n \"\"\"Compute the variance of the elements of x.\"\"\"\n m = mean(x)\n return sum([(elem - m) ** 2 for elem in x]) / len(x)"}
{"task_id": "DSP/265", "completion": "def var(x):\n \"\"\"Compute the variance of the elements of x.\"\"\"\n m = mean(x)\n return sum([(elem - m) ** 2 for elem in x]) / len(x)"}
{"task_id": "DSP/266", "completion": "def std(x):\n \"\"\"Compute the standard deviation of the elements of x.\"\"\"\n return math.sqrt(var(x))"}
{"task_id": "DSP/266", "completion": "def std(x):\n \"\"\"Compute the standard deviation of the elements of x.\"\"\"\n return math.sqrt(var(x))"}
{"task_id": "DSP/267", "completion": "np.random.seed(0) # keep this line to reset the random number generator\n\nsim1 = np.random.poisson(t1_avg, n)\nsim2 = np.random.poisson(t2_avg, n)"}
{"task_id": "DSP/267", "completion": "np.random.seed(0) # keep this line to reset the random number generator\n\nsim1 = np.random.poisson(t1_avg, n)\nsim2 = np.random.poisson(t2_avg, n)"}
{"task_id": "DSP/268", "completion": "spread = sim2 - sim1"}
{"task_id": "DSP/268", "completion": "spread = sim2 - sim1"}
{"task_id": "DSP/269", "completion": "def uniform2(mu, sigma, size=1):\n \"\"\"Return uniform random variates with mean mu and standard dev sigma.\"\"\"\n d = np.sqrt(3 * sigma ** 2)\n a = mu - d\n b = mu + d\n return np.random.uniform(a, b, size=size)"}
{"task_id": "DSP/269", "completion": "def uniform2(mu, sigma, size=1):\n \"\"\"Return uniform random variates with mean mu and standard dev sigma.\"\"\"\n d = np.sqrt(3 * sigma ** 2)\n a = mu - d\n b = mu + d\n return np.random.uniform(a, b, size=size)"}
{"task_id": "DSP/270", "completion": "data = None\nwith open('speed_of_light.txt', 'r') as speed_file:\n data_list = []\n for line in speed_file:\n for string_time in line.split(\" \"):\n data_list.append({'raw': int(string_time)})\n data = pd.DataFrame.from_records(data_list)"}
{"task_id": "DSP/270", "completion": "data = None\nwith open('speed_of_light.txt', 'r') as speed_file:\n data_list = []\n for line in speed_file:\n for string_time in line.split(\" \"):\n data_list.append({'raw': int(string_time)})\n data = pd.DataFrame.from_records(data_list)"}
{"task_id": "DSP/271", "completion": "data['time'] = data['raw'] + offset\ndata['speed'] = distance / data['time']"}
{"task_id": "DSP/271", "completion": "data['time'] = data['raw'] + offset\ndata['speed'] = distance / data['time']"}
{"task_id": "DSP/272", "completion": "df.state = df.state.where(df.state != '', None)"}
{"task_id": "DSP/272", "completion": "df.state = df.state.where(df.state != '', None)"}
{"task_id": "DSP/273", "completion": "df2 = df.dropna(how='any')"}
{"task_id": "DSP/273", "completion": "df2 = df.dropna(how='any')"}
{"task_id": "DSP/274", "completion": "df3 = df.dropna(how='all')"}
{"task_id": "DSP/274", "completion": "df3 = df.dropna(how='all')"}
{"task_id": "DSP/275", "completion": "df4 = df.loc[:, df.count() >= 7]"}
{"task_id": "DSP/275", "completion": "df4 = df.loc[:, df.count() >= 7]"}
{"task_id": "DSP/276", "completion": "df5 = df.select_dtypes(include=[np.number]).fillna(value=-9)"}
{"task_id": "DSP/276", "completion": "df5 = df.select_dtypes(include=[np.number]).fillna(value=-9)"}
{"task_id": "DSP/277", "completion": "def count_null(column):\n \"\"\"Count the number of missing values in a column (Series).\"\"\"\n return column.isnull().sum()"}
{"task_id": "DSP/277", "completion": "def count_null(column):\n \"\"\"Count the number of missing values in a column (Series).\"\"\"\n return column.isnull().sum()"}
{"task_id": "DSP/278", "completion": "ce = create_engine('sqlite:///data/Chinook_Sqlite.sqlite')"}
{"task_id": "DSP/278", "completion": "ce = create_engine('sqlite:///data/Chinook_Sqlite.sqlite')"}
{"task_id": "DSP/279", "completion": "inspector = inspect(ce)"}
{"task_id": "DSP/279", "completion": "inspector = inspect(ce)"}
{"task_id": "DSP/280", "completion": "def soliton(x, t, c, a):\n \"\"\"Return phi(x, t) for a soliton wave with constants c and a.\"\"\"\n return (1 / 2) * c * (1 / np.power(np.cosh((np.sqrt(c) / 2) * (x - c * t - a)), 2))"}
{"task_id": "DSP/280", "completion": "def soliton(x, t, c, a):\n \"\"\"Return phi(x, t) for a soliton wave with constants c and a.\"\"\"\n return (1 / 2) * c * (1 / np.power(np.cosh((np.sqrt(c) / 2) * (x - c * t - a)), 2))"}
{"task_id": "DSP/281", "completion": "X, T = np.meshgrid(x, t, indexing='ij')\nphi = soliton(X, T, c, a)"}
{"task_id": "DSP/281", "completion": "X, T = np.meshgrid(x, t, indexing='ij')\nphi = soliton(X, T, c, a)"}
{"task_id": "DSP/282", "completion": "def add_1(x):\n return x+1\ndef incr_list_by_1(x):\n return[add_1(i) for i in x]"}
{"task_id": "DSP/282", "completion": "def add_1(x):\n return x+1\ndef incr_list_by_1(x):\n return[add_1(i) for i in x]"}
{"task_id": "DSP/283", "completion": "def generate(n, seed):\n \"\"\"Generate a dataset with two dependent but uncorrelated features.\n \n Parameters\n ----------\n n : int\n Number of samples to generate.\n seed : int\n Seed to use for reproducible random numbers.\n \n Returns\n -------\n tuple\n Tuple (X, rho) of generated data X with shape (n, 2) and the\n correlation coefficient rho of the generated data.\n \"\"\"\n gen = np.random.RandomState(seed=seed)\n x1 = gen.uniform(-1,1,n)\n x2 = abs(x1)\n X = np.vstack((x1,x2))\n print(np.corrcoef(X))\n return (X.T,np.corrcoef(X)[0,1])\n # YOUR CODE HERE\n raise NotImplementedError()"}
{"task_id": "DSP/283", "completion": "def generate(n, seed):\n \"\"\"Generate a dataset with two dependent but uncorrelated features.\n \n Parameters\n ----------\n n : int\n Number of samples to generate.\n seed : int\n Seed to use for reproducible random numbers.\n \n Returns\n -------\n tuple\n Tuple (X, rho) of generated data X with shape (n, 2) and the\n correlation coefficient rho of the generated data.\n \"\"\"\n gen = np.random.RandomState(seed=seed)\n x1 = gen.uniform(-1,1,n)\n x2 = abs(x1)\n X = np.vstack((x1,x2))\n print(np.corrcoef(X))\n return (X.T,np.corrcoef(X)[0,1])\n # YOUR CODE HERE\n raise NotImplementedError()"}
{"task_id": "DSP/284", "completion": "def metropolis_update(x, y, s, gen, sigma=1):\n \"\"\"Perform a single Metropolis update.\n \n Parameters\n ----------\n x : float\n Value of x from the previous step.\n y : float\n Value of y from the previous step.\n s : float\n Value of the hyperparameter s.\n gen : np.random.RandomState\n Random state to use for reproducible random samples.\n sigma : float\n Standard deviation of the Gaussian proposal distribution Q(x,y).\n \n Returns\n -------\n tuple\n Tuple (x,y) of the position after the update.\n\n \"\"\"\n C = [[sigma,0],[0,sigma]]\n x0 = [x,y]\n diff = gen.multivariate_normal([0,0],C)\n x1 = x0+diff\n log_ratio = np.log(P(x1[0],x1[1],s)) - np.log(P(x0[0],x0[1],s)) \n if log_ratio >= 0:\n return x1\n else:\n accept_prob = np.exp(log_ratio)\n return x1 if gen.uniform() < accept_prob else x0\n # YOUR CODE HERE\n raise NotImplementedError()"}
{"task_id": "DSP/284", "completion": "def metropolis_update(x, y, s, gen, sigma=1):\n \"\"\"Perform a single Metropolis update.\n \n Parameters\n ----------\n x : float\n Value of x from the previous step.\n y : float\n Value of y from the previous step.\n s : float\n Value of the hyperparameter s.\n gen : np.random.RandomState\n Random state to use for reproducible random samples.\n sigma : float\n Standard deviation of the Gaussian proposal distribution Q(x,y).\n \n Returns\n -------\n tuple\n Tuple (x,y) of the position after the update.\n\n \"\"\"\n C = [[sigma,0],[0,sigma]]\n x0 = [x,y]\n diff = gen.multivariate_normal([0,0],C)\n x1 = x0+diff\n log_ratio = np.log(P(x1[0],x1[1],s)) - np.log(P(x0[0],x0[1],s)) \n if log_ratio >= 0:\n return x1\n else:\n accept_prob = np.exp(log_ratio)\n return x1 if gen.uniform() < accept_prob else x0\n # YOUR CODE HERE\n raise NotImplementedError()"}
{"task_id": "DSP/285", "completion": "def sample_conditional(y, s, gen):\n \"\"\"Sample from the conditional distribution P(x | y).\n \n Parameters\n ----------\n y : float\n Fixed value of y to use.\n s : float\n Value of the hyperparameter s.\n gen : np.random.RandomState\n Random state to use for reproducible random samples.\n \n Returns\n -------\n float\n Random value of x sampled from P(x | y).\n \"\"\"\n w1 = np.exp(-0.5*(y*s)**2)\n w2 = np.exp(-0.5*(y/s)**2)\n accept_prob = w2/(w1+w2)\n if gen.uniform() < accept_prob:\n x = gen.normal(0,1/s)\n else:\n x = gen.normal(0,s)\n return x \n \n # YOUR CODE HERE\n raise NotImplementedError()"}
{"task_id": "DSP/285", "completion": "def sample_conditional(y, s, gen):\n \"\"\"Sample from the conditional distribution P(x | y).\n \n Parameters\n ----------\n y : float\n Fixed value of y to use.\n s : float\n Value of the hyperparameter s.\n gen : np.random.RandomState\n Random state to use for reproducible random samples.\n \n Returns\n -------\n float\n Random value of x sampled from P(x | y).\n \"\"\"\n w1 = np.exp(-0.5*(y*s)**2)\n w2 = np.exp(-0.5*(y/s)**2)\n accept_prob = w2/(w1+w2)\n if gen.uniform() < accept_prob:\n x = gen.normal(0,1/s)\n else:\n x = gen.normal(0,s)\n return x \n \n # YOUR CODE HERE\n raise NotImplementedError()"}
{"task_id": "DSP/286", "completion": "def gibbs_update(x, y, s, gen):\n \"\"\"Perform a single Gibbs update.\n \n Parameters\n ----------\n x : float\n Value of x from the previous step.\n y : float\n Value of y from the previous step.\n s : float\n Value of the hyperparameter s.\n gen : np.random.RandomState\n Random state to use for reproducible random samples.\n \n Returns\n -------\n tuple\n Tuple (x,y) of the position after the update.\n \"\"\"\n xnew = sample_conditional(y,s,gen)\n ynew = sample_conditional(xnew,s,gen)\n return (xnew,ynew)\n # YOUR CODE HERE\n raise NotImplementedError()"}
{"task_id": "DSP/286", "completion": "def gibbs_update(x, y, s, gen):\n \"\"\"Perform a single Gibbs update.\n \n Parameters\n ----------\n x : float\n Value of x from the previous step.\n y : float\n Value of y from the previous step.\n s : float\n Value of the hyperparameter s.\n gen : np.random.RandomState\n Random state to use for reproducible random samples.\n \n Returns\n -------\n tuple\n Tuple (x,y) of the position after the update.\n \"\"\"\n xnew = sample_conditional(y,s,gen)\n ynew = sample_conditional(xnew,s,gen)\n return (xnew,ynew)\n # YOUR CODE HERE\n raise NotImplementedError()"}
{"task_id": "DSP/287", "completion": "def HMC_step(x, y, px, py, s, dt):\n \"\"\"Perform a single HMC dt step.\n \n Parameters\n ----------\n x : float\n Current x position.\n y : float\n Current y position.\n px : float\n Current x momentum.\n py : float\n Current y momentum.\n s : float\n Value of the hyperparameter s.\n dt : float\n Step size to take.\n \n Returns\n -------\n tuple\n Tuple (x, y, px, py) with particle position and momentum after this step.\n \"\"\"\n def E1(x,y,s):\n return 0.5 * (np.exp(-0.5 * ((x / s) ** 2 + (y * s) ** 2)))\n def E2(x,y,s):\n return 0.5 * (np.exp(-0.5 * ((x * s) ** 2 + (y / s) ** 2)))\n def dUdx(x,y,s):\n return x*(E1(x,y,s)/s**2 + E2(x,y,s)*s**2)/(E1(x,y,s)+E2(x,y,s))\n def dUdy(d,y,s):\n return y*(E1(x,y,s)*s**2 + E2(x,y,s)/s**2)/(E1(x,y,s)+E2(x,y,s))\n\n xnew = x + px*dt\n ynew = y + py*dt\n pxnew = px - dUdx(x,y,s)*dt\n pynew = py - dUdy(x,y,s)*dt\n return (xnew,ynew,pxnew,pynew)\n # YOUR CODE HERE\n raise NotImplementedError()"}
{"task_id": "DSP/287", "completion": "def HMC_step(x, y, px, py, s, dt):\n \"\"\"Perform a single HMC dt step.\n \n Parameters\n ----------\n x : float\n Current x position.\n y : float\n Current y position.\n px : float\n Current x momentum.\n py : float\n Current y momentum.\n s : float\n Value of the hyperparameter s.\n dt : float\n Step size to take.\n \n Returns\n -------\n tuple\n Tuple (x, y, px, py) with particle position and momentum after this step.\n \"\"\"\n def E1(x,y,s):\n return 0.5 * (np.exp(-0.5 * ((x / s) ** 2 + (y * s) ** 2)))\n def E2(x,y,s):\n return 0.5 * (np.exp(-0.5 * ((x * s) ** 2 + (y / s) ** 2)))\n def dUdx(x,y,s):\n return x*(E1(x,y,s)/s**2 + E2(x,y,s)*s**2)/(E1(x,y,s)+E2(x,y,s))\n def dUdy(d,y,s):\n return y*(E1(x,y,s)*s**2 + E2(x,y,s)/s**2)/(E1(x,y,s)+E2(x,y,s))\n\n xnew = x + px*dt\n ynew = y + py*dt\n pxnew = px - dUdx(x,y,s)*dt\n pynew = py - dUdy(x,y,s)*dt\n return (xnew,ynew,pxnew,pynew)\n # YOUR CODE HERE\n raise NotImplementedError()"}
{"task_id": "DSP/288", "completion": "def rmse(observed,predicted):\n '''Compute the root mean squared error between the two lists of samples: observed and predicted.'''\n ### BEGIN SOLUTION\n return np.sqrt(((observed-predicted)**2).mean())\n ### END SOLUTION\n\n# test \nrmse(observed,predicted)"}
{"task_id": "DSP/288", "completion": "def rmse(observed,predicted):\n '''Compute the root mean squared error between the two lists of samples: observed and predicted.'''\n ### BEGIN SOLUTION\n return np.sqrt(((observed-predicted)**2).mean())\n ### END SOLUTION\n\n# test \nrmse(observed,predicted)"}
{"task_id": "DSP/289", "completion": "Rmse = None # replace with your answer\nRmse\n### BEGIN SOLUTION\nRmse = np.sqrt(((observed-predicted)**2).mean())\n### END SOLUTION"}
{"task_id": "DSP/289", "completion": "Rmse = None # replace with your answer\nRmse\n### BEGIN SOLUTION\nRmse = np.sqrt(((observed-predicted)**2).mean())\n### END SOLUTION"}
{"task_id": "DSP/290", "completion": "answer= None # replace with your answer\nanswer\n### BEGIN SOLUTION\n \nanswer =round(np.sqrt(((observed-predicted)**2).mean()),2)\n### END SOLUTION"}
{"task_id": "DSP/290", "completion": "answer= None # replace with your answer\nanswer\n### BEGIN SOLUTION\n \nanswer =round(np.sqrt(((observed-predicted)**2).mean()),2)\n### END SOLUTION"}
{"task_id": "DSP/291", "completion": "def intro_dictionary(name, hometown, department, status, years):\n \"\"\"Returns a dictionary containing key/value pairs.\n \n Parameters\n ----------\n name : string\n Your name\n hometown : string\n Where are you from?\n department : string\n What department are you in?\n status : string\n Are you an undergrad or graduate student?\n years : float\n How many years have you been at TAMU?\n \n Returns\n -------\n dictionary containing the input information\n \n \"\"\"\n # YOUR CODE HERE\n return {'name': name, 'hometown': hometown,'department':department,'status':status,'years':years} \nintro_dictionary('Xiao', 'Xiangyang', 'Oceanography', 'Graduate', 1)"}
{"task_id": "DSP/291", "completion": "def intro_dictionary(name, hometown, department, status, years):\n \"\"\"Returns a dictionary containing key/value pairs.\n \n Parameters\n ----------\n name : string\n Your name\n hometown : string\n Where are you from?\n department : string\n What department are you in?\n status : string\n Are you an undergrad or graduate student?\n years : float\n How many years have you been at TAMU?\n \n Returns\n -------\n dictionary containing the input information\n \n \"\"\"\n # YOUR CODE HERE\n return {'name': name, 'hometown': hometown,'department':department,'status':status,'years':years} \nintro_dictionary('Xiao', 'Xiangyang', 'Oceanography', 'Graduate', 1)"}
{"task_id": "DSP/292", "completion": "def isVowel(char):\n \"\"\"Takes a character and returns True if it is a vowel, and False otherwise.\n \n Parameters\n ----------\n char : string\n string of length 1\n \n Returns\n -------\n boolean telling whether char is a vowel or not\n \n \"\"\"\n # YOUR CODE HERE\n return any(char.lower() == c for c in 'aeiou')"}
{"task_id": "DSP/292", "completion": "def isVowel(char):\n \"\"\"Takes a character and returns True if it is a vowel, and False otherwise.\n \n Parameters\n ----------\n char : string\n string of length 1\n \n Returns\n -------\n boolean telling whether char is a vowel or not\n \n \"\"\"\n # YOUR CODE HERE\n return any(char.lower() == c for c in 'aeiou')"}
{"task_id": "DSP/293", "completion": "def reverse(string):\n \"\"\"Reverse string and then return in.\n \n Parameters\n ----------\n string : str\n \n \n Returns\n -------\n string that is reversed\n \"\"\"\n # YOUR CODE HERE\n return string[::-1]"}
{"task_id": "DSP/293", "completion": "def reverse(string):\n \"\"\"Reverse string and then return in.\n \n Parameters\n ----------\n string : str\n \n \n Returns\n -------\n string that is reversed\n \"\"\"\n # YOUR CODE HERE\n return string[::-1]"}
{"task_id": "DSP/294", "completion": "def length(inputs):\n \"\"\"Compute the length of a given list or string.\n \n Parameters\n ----------\n inputs : string or list\n \n \n Returns\n -------\n integer that is either the number of characters in the input string or the number of \n entries in the input list.\n \"\"\"\n # YOUR CODE HERE\n \n if inputs.count(inputs[-1]) > 1:\n return inputs.rindex(inputs[-1])+1\n else:\n return inputs.index(inputs[-1])+1"}
{"task_id": "DSP/294", "completion": "def length(inputs):\n \"\"\"Compute the length of a given list or string.\n \n Parameters\n ----------\n inputs : string or list\n \n \n Returns\n -------\n integer that is either the number of characters in the input string or the number of \n entries in the input list.\n \"\"\"\n # YOUR CODE HERE\n \n if inputs.count(inputs[-1]) > 1:\n return inputs.rindex(inputs[-1])+1\n else:\n return inputs.index(inputs[-1])+1"}
{"task_id": "DSP/295", "completion": "def is_palindrome(phrase):\n \"\"\"Returns True for a palindrome and False otherwise.\n \n Parameters\n ----------\n phrase : string\n \n \n Returns\n -------\n Boolean\n \"\"\"\n # YOUR CODE HERE\n phrasenew=phrase.replace(\" \",\"\").lower()\n return phrasenew[::-1]==phrasenew"}
{"task_id": "DSP/295", "completion": "def is_palindrome(phrase):\n \"\"\"Returns True for a palindrome and False otherwise.\n \n Parameters\n ----------\n phrase : string\n \n \n Returns\n -------\n Boolean\n \"\"\"\n # YOUR CODE HERE\n phrasenew=phrase.replace(\" \",\"\").lower()\n return phrasenew[::-1]==phrasenew"}
{"task_id": "DSP/296", "completion": "key = {'a':'n', 'b':'o', 'c':'p', 'd':'q', 'e':'r', 'f':'s', 'g':'t', 'h':'u', \n 'i':'v', 'j':'w', 'k':'x', 'l':'y', 'm':'z', 'n':'a', 'o':'b', 'p':'c', \n 'q':'d', 'r':'e', 's':'f', 't':'g', 'u':'h', 'v':'i', 'w':'j', 'x':'k',\n 'y':'l', 'z':'m', 'A':'N', 'B':'O', 'C':'P', 'D':'Q', 'E':'R', 'F':'S', \n 'G':'T', 'H':'U', 'I':'V', 'J':'W', 'K':'X', 'L':'Y', 'M':'Z', 'N':'A', \n 'O':'B', 'P':'C', 'Q':'D', 'R':'E', 'S':'F', 'T':'G', 'U':'H', 'V':'I', \n 'W':'J', 'X':'K', 'Y':'L', 'Z':'M'}\n\ndef rot13(letter):\n \"\"\"Swap letter indicated in key.\n \n Parameters\n ----------\n letter : string of length 1\n letter to be swapped using the key dictionary\n \n Returns\n -------\n letter\n \"\"\"\n # YOUR CODE HERE\n keydecode=''\n for i in letter:\n if i.islower():\n keydecode+=key.get(i) \n if i.isupper():\n i=i.lower()\n keydecode+=key.get(i).capitalize()\n if i not in key:\n keydecode+=i\n \n \n return keydecode"}
{"task_id": "DSP/296", "completion": "key = {'a':'n', 'b':'o', 'c':'p', 'd':'q', 'e':'r', 'f':'s', 'g':'t', 'h':'u', \n 'i':'v', 'j':'w', 'k':'x', 'l':'y', 'm':'z', 'n':'a', 'o':'b', 'p':'c', \n 'q':'d', 'r':'e', 's':'f', 't':'g', 'u':'h', 'v':'i', 'w':'j', 'x':'k',\n 'y':'l', 'z':'m', 'A':'N', 'B':'O', 'C':'P', 'D':'Q', 'E':'R', 'F':'S', \n 'G':'T', 'H':'U', 'I':'V', 'J':'W', 'K':'X', 'L':'Y', 'M':'Z', 'N':'A', \n 'O':'B', 'P':'C', 'Q':'D', 'R':'E', 'S':'F', 'T':'G', 'U':'H', 'V':'I', \n 'W':'J', 'X':'K', 'Y':'L', 'Z':'M'}\n\ndef rot13(letter):\n \"\"\"Swap letter indicated in key.\n \n Parameters\n ----------\n letter : string of length 1\n letter to be swapped using the key dictionary\n \n Returns\n -------\n letter\n \"\"\"\n # YOUR CODE HERE\n keydecode=''\n for i in letter:\n if i.islower():\n keydecode+=key.get(i) \n if i.isupper():\n i=i.lower()\n keydecode+=key.get(i).capitalize()\n if i not in key:\n keydecode+=i\n \n \n return keydecode"}
{"task_id": "DSP/297", "completion": "def words(num):\n \"\"\"Returns words with proper number of beer bottles filled in.\"\"\"\n \n if num != 1:\n return str(num) + ' bottles of beer on the wall, ' + str(num) + ' bottles of beer.\\n' + \\\n 'Take one down, pass it around, ' + str(num-1) + ' bottles of beer on the wall.\\n\\n'\n\n elif num == 1:\n return str(num) + ' bottle of beer on the wall, ' + str(num) + ' bottle of beer.\\n' + \\\n 'Take one down, pass it around, ' + str(num-1) + ' bottles of beer on the wall.'\n \ndef connect_words(numbottles):\n \n listofwords = []\n for i in range(numbottles, 0, -1):\n listofwords.append(words(i))\n \n return listofwords\n \n# YOUR CODE HERE"}
{"task_id": "DSP/297", "completion": "def words(num):\n \"\"\"Returns words with proper number of beer bottles filled in.\"\"\"\n \n if num != 1:\n return str(num) + ' bottles of beer on the wall, ' + str(num) + ' bottles of beer.\\n' + \\\n 'Take one down, pass it around, ' + str(num-1) + ' bottles of beer on the wall.\\n\\n'\n\n elif num == 1:\n return str(num) + ' bottle of beer on the wall, ' + str(num) + ' bottle of beer.\\n' + \\\n 'Take one down, pass it around, ' + str(num-1) + ' bottles of beer on the wall.'\n \ndef connect_words(numbottles):\n \n listofwords = []\n for i in range(numbottles, 0, -1):\n listofwords.append(words(i))\n \n return listofwords\n \n# YOUR CODE HERE"}
{"task_id": "DSP/298", "completion": "def vector_manipulation():\n \"\"\"Returns a vector of zeros of size 10 but with the fifth value as 1.\n \"\"\"\n # YOUR CODE HERE\n z=np.zeros(10)\n z[4]=1\n return z"}
{"task_id": "DSP/298", "completion": "def vector_manipulation():\n \"\"\"Returns a vector of zeros of size 10 but with the fifth value as 1.\n \"\"\"\n # YOUR CODE HERE\n z=np.zeros(10)\n z[4]=1\n return z"}
{"task_id": "DSP/299", "completion": "def vector_range():\n \"\"\"Returns a vector with values ranging from 10 to 49, inclusive.\n \"\"\"\n # YOUR CODE HERE\n return np.arange(10,50)"}
{"task_id": "DSP/299", "completion": "def vector_range():\n \"\"\"Returns a vector with values ranging from 10 to 49, inclusive.\n \"\"\"\n # YOUR CODE HERE\n return np.arange(10,50)"}
{"task_id": "DSP/300", "completion": "def arg_nonzero(x):\n \"\"\"return the indices of non-zero elements of an array.\n\n Inputs:\n x: array\n \n Returns:\n indices: array of integer indices\n \"\"\"\n # YOUR CODE HERE\n return np.where(x != 0)[0]"}
{"task_id": "DSP/300", "completion": "def arg_nonzero(x):\n \"\"\"return the indices of non-zero elements of an array.\n\n Inputs:\n x: array\n \n Returns:\n indices: array of integer indices\n \"\"\"\n # YOUR CODE HERE\n return np.where(x != 0)[0]"}
{"task_id": "DSP/301", "completion": "def return_nonzero(x, ind):\n \"\"\"return the indices of non-zero elements of an array.\n\n Inputs:\n x: array\n output: results from call to find_nonzero(x)\n \n Returns:\n indices of non-zero element in x\n \"\"\"\n # YOUR CODE HERE\n# for id in ind():\n# x2 = np.array([x[id]])\n\n return np.array([x[id] for id in ind])"}
{"task_id": "DSP/301", "completion": "def return_nonzero(x, ind):\n \"\"\"return the indices of non-zero elements of an array.\n\n Inputs:\n x: array\n output: results from call to find_nonzero(x)\n \n Returns:\n indices of non-zero element in x\n \"\"\"\n # YOUR CODE HERE\n# for id in ind():\n# x2 = np.array([x[id]])\n\n return np.array([x[id] for id in ind])"}
{"task_id": "DSP/302", "completion": "def maxesmins(K):\n \"\"\"Returns the min of the 2nd row and max of the 4th column.\n\n Parameters\n ----------\n K : numpy array\n \n Returns\n -------\n min of the 2nd row and max of the 4th column, as a tuple, or a nan for either if the array is too small to calculate it\n \"\"\"\n # YOUR CODE HERE\n z=[np.nan,np.nan]\n if K[:,0].size>=2:\n z[0]=K[1,:].min()\n if K[0,:].size>=4: \n z[1]=K[:,3].max()\n return tuple(z)\n# if it's a three dimension?"}
{"task_id": "DSP/302", "completion": "def maxesmins(K):\n \"\"\"Returns the min of the 2nd row and max of the 4th column.\n\n Parameters\n ----------\n K : numpy array\n \n Returns\n -------\n min of the 2nd row and max of the 4th column, as a tuple, or a nan for either if the array is too small to calculate it\n \"\"\"\n # YOUR CODE HERE\n z=[np.nan,np.nan]\n if K[:,0].size>=2:\n z[0]=K[1,:].min()\n if K[0,:].size>=4: \n z[1]=K[:,3].max()\n return tuple(z)\n# if it's a three dimension?"}
{"task_id": "DSP/303", "completion": "def sorted_array():\n \"\"\"Creates, sorts, and returns a vector of size 10 filled with random numbers\n \"\"\"\n # YOUR CODE HERE\n a=np.random.rand(10)\n return np.sort(a)"}
{"task_id": "DSP/303", "completion": "def sorted_array():\n \"\"\"Creates, sorts, and returns a vector of size 10 filled with random numbers\n \"\"\"\n # YOUR CODE HERE\n a=np.random.rand(10)\n return np.sort(a)"}
{"task_id": "DSP/304", "completion": "collisions_subset = collisions.loc[:, ['DATETIME', 'TIME', 'START', 'END', 'DATE', 'LATITUDE', 'LONGITUDE', 'SEVERITY']]\n\ncollisions_subset.head(5)"}
{"task_id": "DSP/304", "completion": "collisions_subset = collisions.loc[:, ['DATETIME', 'TIME', 'START', 'END', 'DATE', 'LATITUDE', 'LONGITUDE', 'SEVERITY']]\n\ncollisions_subset.head(5)"}
{"task_id": "DSP/305", "completion": "merged = train_df.merge(collisions_subset, how='left', left_on='date', right_on='DATE')\n\nmerged.head()"}
{"task_id": "DSP/305", "completion": "merged = train_df.merge(collisions_subset, how='left', left_on='date', right_on='DATE')\n\nmerged.head()"}
{"task_id": "DSP/306", "completion": "start_to_accident = haversine(merged['pickup_latitude'].values,\n merged['pickup_longitude'].values,\n merged['LATITUDE'].values,\n merged['LONGITUDE'].values)\nmerged['start_to_accident'] = start_to_accident\n\n# initialze accident_close column to all 0 first\nmerged['accident_close'] = 0\n\n# # Boolean pd.Series to select the indices for which accident_close should equal 1:\n# # (1) record's start_to_accident <= 5 \n# # (2) pick up time is between start and end\nis_accident_close = (merged['start_to_accident'] <= 5) & (merged['tpep_pickup_datetime'] >= merged['START']) & (merged['tpep_pickup_datetime'] <= merged['END'])\n\nmerged.loc[is_accident_close, 'accident_close'] = 1"}
{"task_id": "DSP/306", "completion": "start_to_accident = haversine(merged['pickup_latitude'].values,\n merged['pickup_longitude'].values,\n merged['LATITUDE'].values,\n merged['LONGITUDE'].values)\nmerged['start_to_accident'] = start_to_accident\n\n# initialze accident_close column to all 0 first\nmerged['accident_close'] = 0\n\n# # Boolean pd.Series to select the indices for which accident_close should equal 1:\n# # (1) record's start_to_accident <= 5 \n# # (2) pick up time is between start and end\nis_accident_close = (merged['start_to_accident'] <= 5) & (merged['tpep_pickup_datetime'] >= merged['START']) & (merged['tpep_pickup_datetime'] <= merged['END'])\n\nmerged.loc[is_accident_close, 'accident_close'] = 1"}
{"task_id": "DSP/307", "completion": "calls_by_cvlegend_and_offense = calls.groupby(['CVLEGEND', 'OFFENSE']).size()"}
{"task_id": "DSP/307", "completion": "calls_by_cvlegend_and_offense = calls.groupby(['CVLEGEND', 'OFFENSE']).size()"}
{"task_id": "DSP/308", "completion": "answer1b = list(calls.loc[calls['CVLEGEND']=='LARCENY']['OFFENSE'].unique())"}
{"task_id": "DSP/308", "completion": "answer1b = list(calls.loc[calls['CVLEGEND']=='LARCENY']['OFFENSE'].unique())"}
{"task_id": "DSP/309", "completion": "answer2 = list(calls['CVLEGEND'].value_counts().head(5).keys())"}
{"task_id": "DSP/309", "completion": "answer2 = list(calls['CVLEGEND'].value_counts().head(5).keys())"}
{"task_id": "DSP/310", "completion": "days = [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]\nday_indices = range(7)\nindices_to_days_dict = dict(zip(day_indices, days)) # Should look like {0:\"Sunday\", 1:\"Monday\", ..., 6:\"Saturday\"}\n\ncalls['Day'] = calls['CVDOW'].map(indices_to_days_dict)"}
{"task_id": "DSP/310", "completion": "days = [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]\nday_indices = range(7)\nindices_to_days_dict = dict(zip(day_indices, days)) # Should look like {0:\"Sunday\", 1:\"Monday\", ..., 6:\"Saturday\"}\n\ncalls['Day'] = calls['CVDOW'].map(indices_to_days_dict)"}
{"task_id": "DSP/311", "completion": "ax = calls['Day'].value_counts()[days].plot.bar(x='Day', y='Number of Calls')\nax.set_xlabel('Day')\nax.set_ylabel('Number of Calls')\n\n# Leave this for grading purposes\nax_3b = plt.gca()"}
{"task_id": "DSP/311", "completion": "ax = calls['Day'].value_counts()[days].plot.bar(x='Day', y='Number of Calls')\nax.set_xlabel('Day')\nax.set_ylabel('Number of Calls')\n\n# Leave this for grading purposes\nax_3b = plt.gca()"}
{"task_id": "DSP/312", "completion": "ax = sns.countplot(x=calls.loc[calls['CVLEGEND'] == 'NOISE VIOLATION']['Day'], order=days)\nax.set_title(\"Number of Toal Noise Violation For Each Day of the Week\");\nax_4a = plt.gca()"}
{"task_id": "DSP/312", "completion": "ax = sns.countplot(x=calls.loc[calls['CVLEGEND'] == 'NOISE VIOLATION']['Day'], order=days)\nax.set_title(\"Number of Toal Noise Violation For Each Day of the Week\");\nax_4a = plt.gca()"}
{"task_id": "DSP/313", "completion": "ax = sns.countplot(x=calls.loc[calls['CVLEGEND'] == 'FRAUD']['Day'], order=days)\nax.set_title(\"Number of Toal Fraud For Each Day of the Week\");\n\n# Leave this for grading purposes\nax_5 = plt.gca()"}
{"task_id": "DSP/313", "completion": "ax = sns.countplot(x=calls.loc[calls['CVLEGEND'] == 'FRAUD']['Day'], order=days)\nax.set_title(\"Number of Toal Fraud For Each Day of the Week\");\n\n# Leave this for grading purposes\nax_5 = plt.gca()"}
{"task_id": "DSP/314", "completion": "calls['Hour'] = calls['EVENTTM'].str.slice(0,2).astype('int')"}
{"task_id": "DSP/314", "completion": "calls['Hour'] = calls['EVENTTM'].str.slice(0,2).astype('int')"}
{"task_id": "DSP/315", "completion": "ax = sns.countplot(calls.loc[calls['CVLEGEND']=='FRAUD']['Hour'])\nax.set_xlabel(\"Hour of the Day\")\nax.set_ylabel(\"Number of Calls\")\nax.set_title(\"Number of Calls Reporting Fraud For Each Day of the Week\");\n\n# Leave this for grading purposes\nax_6b = plt.gca()"}
{"task_id": "DSP/315", "completion": "ax = sns.countplot(calls.loc[calls['CVLEGEND']=='FRAUD']['Hour'])\nax.set_xlabel(\"Hour of the Day\")\nax.set_ylabel(\"Number of Calls\")\nax.set_title(\"Number of Calls Reporting Fraud For Each Day of the Week\");\n\n# Leave this for grading purposes\nax_6b = plt.gca()"}
{"task_id": "DSP/316", "completion": "answer7 = 'SEX CRIME'"}
{"task_id": "DSP/316", "completion": "answer7 = 'SEX CRIME'"}
{"task_id": "DSP/317", "completion": "def bootstrap(boot_pop, statistic, resample, replicates = 1000):\n \"\"\"\n Args:\n boot_pop: an array of shape n x d.\n statistic: a function which takes boot_pop and returns a number.\n resample: a function which takes n and returns a random sample from the integers [0, n)\n replicates: the number of resamples\n \n Returns:\n an array of length replicates, each entry being the statistic computed on a bootstrap sample of the data.\n \"\"\"\n return np.array([statistic(boot_pop[resample(len(boot_pop))]) for _ in range(replicates)])"}
{"task_id": "DSP/317", "completion": "def bootstrap(boot_pop, statistic, resample, replicates = 1000):\n \"\"\"\n Args:\n boot_pop: an array of shape n x d.\n statistic: a function which takes boot_pop and returns a number.\n resample: a function which takes n and returns a random sample from the integers [0, n)\n replicates: the number of resamples\n \n Returns:\n an array of length replicates, each entry being the statistic computed on a bootstrap sample of the data.\n \"\"\"\n return np.array([statistic(boot_pop[resample(len(boot_pop))]) for _ in range(replicates)])"}
{"task_id": "DSP/318", "completion": "m = 1000\nboot_pop = np.array(data[\"Grade\"])\n\nboot_sample_std = bootstrap(boot_pop, np.std, simple_resample, m)"}
{"task_id": "DSP/318", "completion": "m = 1000\nboot_pop = np.array(data[\"Grade\"])\n\nboot_sample_std = bootstrap(boot_pop, np.std, simple_resample, m)"}
{"task_id": "DSP/319", "completion": "def estimator(d):\n \"\"\"\n Args:\n d: A n*2 array which contains x and y. d[:,0] would be x, d[:,1] would be y.\n \n Returns:\n The optimal theta for this dataset under L2 loss.\n \"\"\"\n return np.dot(d[:, 0], d[:, 1]) / (np.dot(d[:, 0], d[:, 0])).sum()"}
{"task_id": "DSP/319", "completion": "def estimator(d):\n \"\"\"\n Args:\n d: A n*2 array which contains x and y. d[:,0] would be x, d[:,1] would be y.\n \n Returns:\n The optimal theta for this dataset under L2 loss.\n \"\"\"\n return np.dot(d[:, 0], d[:, 1]) / (np.dot(d[:, 0], d[:, 0])).sum()"}
{"task_id": "DSP/320", "completion": "replicates = 1000\nboot_theta = bootstrap(d, estimator, simple_resample, replicates)"}
{"task_id": "DSP/320", "completion": "replicates = 1000\nboot_theta = bootstrap(d, estimator, simple_resample, replicates)"}
{"task_id": "DSP/321", "completion": "def mean(population):\n return sum([x for x in population])/len(population)\n\ndef variance(population):\n m = mean(population)\n return sum([(x - m)**2 for x in population])/len(population)"}
{"task_id": "DSP/321", "completion": "def mean(population):\n return sum([x for x in population])/len(population)\n\ndef variance(population):\n m = mean(population)\n return sum([(x - m)**2 for x in population])/len(population)"}
{"task_id": "DSP/322", "completion": "plt.figure(figsize=(20,10))\n\nsigma = 10\n\n# Loop through index of each channel\nfor channel in range(3):\n # Make a subplot\n plt.subplot(1,3,channel+1)\n \n # FINISH THE CODE\n pic_copy = pic.copy()\n pic_copy[:, :, channel] = skimage.filters.gaussian(pic_copy[:,:,channel], sigma)\n skimage.io.imshow(pic_copy)\n \n plt.grid(False)\n plt.title(channel_names[channel])\n plt.suptitle(\"Blurred channels of an image\")"}
{"task_id": "DSP/322", "completion": "plt.figure(figsize=(20,10))\n\nsigma = 10\n\n# Loop through index of each channel\nfor channel in range(3):\n # Make a subplot\n plt.subplot(1,3,channel+1)\n \n # FINISH THE CODE\n pic_copy = pic.copy()\n pic_copy[:, :, channel] = skimage.filters.gaussian(pic_copy[:,:,channel], sigma)\n skimage.io.imshow(pic_copy)\n \n plt.grid(False)\n plt.title(channel_names[channel])\n plt.suptitle(\"Blurred channels of an image\")"}
{"task_id": "DSP/323", "completion": "def multiply_list_fixed(some_list, multiplier):\n return np.array(some_list) * multiplier"}
{"task_id": "DSP/323", "completion": "def multiply_list_fixed(some_list, multiplier):\n return np.array(some_list) * multiplier"}
{"task_id": "DSP/324", "completion": "def find_all_under_10_fixed(some_list):\n return np.extract(np.array(some_list)<10, np.array(some_list))"}
{"task_id": "DSP/324", "completion": "def find_all_under_10_fixed(some_list):\n return np.extract(np.array(some_list)<10, np.array(some_list))"}
{"task_id": "DSP/325", "completion": "def cat_fixed(cat_data):\n lst = [[x[0],int(x[1])+3] for x in cat_data if int(x[1]) < 10]\n return np.array(lst)"}
{"task_id": "DSP/325", "completion": "def cat_fixed(cat_data):\n lst = [[x[0],int(x[1])+3] for x in cat_data if int(x[1]) < 10]\n return np.array(lst)"}
{"task_id": "DSP/326", "completion": "bike = bike.replace({'weekday' : {0:'Sun', 1:'Mon', 2:'Tue', 3:'Wed', 4:'Thu', 5:'Fri', 6:'Sat'},\n 'holiday':{0:'no', 1:'yes'},\n 'workingday':{0:'no', 1:'yes'},\n 'weathersit':{0:'Clear', 1:'Mist', 2:'Light', 3:'Heavy'}})"}
{"task_id": "DSP/326", "completion": "bike = bike.replace({'weekday' : {0:'Sun', 1:'Mon', 2:'Tue', 3:'Wed', 4:'Thu', 5:'Fri', 6:'Sat'},\n 'holiday':{0:'no', 1:'yes'},\n 'workingday':{0:'no', 1:'yes'},\n 'weathersit':{0:'Clear', 1:'Mist', 2:'Light', 3:'Heavy'}})"}
{"task_id": "DSP/327", "completion": "num_holidays = bike.loc[bike['holiday']=='yes','holiday'].size"}
{"task_id": "DSP/327", "completion": "num_holidays = bike.loc[bike['holiday']=='yes','holiday'].size"}
{"task_id": "DSP/328", "completion": "daily_counts = bike.groupby('dteday').agg({'casual':'sum', 'registered':'sum', 'workingday':'first'})\ndaily_counts.head(5)"}
{"task_id": "DSP/328", "completion": "daily_counts = bike.groupby('dteday').agg({'casual':'sum', 'registered':'sum', 'workingday':'first'})\ndaily_counts.head(5)"}
{"task_id": "DSP/329", "completion": "bike['prop_casual'] = bike['casual'] / bike['cnt']"}
{"task_id": "DSP/329", "completion": "bike['prop_casual'] = bike['casual'] / bike['cnt']"}
{"task_id": "DSP/330", "completion": "def model(theta, total_bill):\n \"\"\"\n Takes the parameter theta and the total bill, and returns the computed tip.\n \n Parameters\n ----------\n theta: tip percentage \n total_bill: total bill value in dollars\n \"\"\"\n return theta * total_bill"}
{"task_id": "DSP/330", "completion": "def model(theta, total_bill):\n \"\"\"\n Takes the parameter theta and the total bill, and returns the computed tip.\n \n Parameters\n ----------\n theta: tip percentage \n total_bill: total bill value in dollars\n \"\"\"\n return theta * total_bill"}
{"task_id": "DSP/331", "completion": "def squared_loss(y_obs, y_hat):\n \"\"\"\n Calculate the squared loss of the observed data and predicted data.\n \n Parameters\n ------------\n y_obs: an array of observed values\n y_hat: an array of predicted values\n \n Returns\n ------------\n An array of loss values corresponding to the squared loss for each prediction\n \"\"\"\n ...\n return (y_obs - y_hat) ** 2"}
{"task_id": "DSP/331", "completion": "def squared_loss(y_obs, y_hat):\n \"\"\"\n Calculate the squared loss of the observed data and predicted data.\n \n Parameters\n ------------\n y_obs: an array of observed values\n y_hat: an array of predicted values\n \n Returns\n ------------\n An array of loss values corresponding to the squared loss for each prediction\n \"\"\"\n ...\n return (y_obs - y_hat) ** 2"}
{"task_id": "DSP/332", "completion": "loss = np.array([ squared_loss(y, model(theta, x)) for theta in thetas])\n# loss.shape\nplt.figure(figsize=(8,5))\nplt.plot(thetas, loss, label='Squared Loss')\nplt.ylabel('Loss')\nplt.xlabel(r'Choice for $\\theta$')\nplt.yticks(np.arange(0, 35, 5))\nplt.legend(loc=4)\nplt.show()"}
{"task_id": "DSP/332", "completion": "loss = np.array([ squared_loss(y, model(theta, x)) for theta in thetas])\n# loss.shape\nplt.figure(figsize=(8,5))\nplt.plot(thetas, loss, label='Squared Loss')\nplt.ylabel('Loss')\nplt.xlabel(r'Choice for $\\theta$')\nplt.yticks(np.arange(0, 35, 5))\nplt.legend(loc=4)\nplt.show()"}
{"task_id": "DSP/333", "completion": "def abs_loss(y_obs, y_hat):\n \"\"\"\n Calculate the absolute loss of the observed data and predicted data.\n \n Parameters\n ------------\n y_obs: an array of observed values\n y_hat: an array of predicted values\n \n Returns\n ------------\n An array of loss values corresponding to the absolute loss for each prediction\n \"\"\"\n ...\n return abs(y_obs - y_hat)"}
{"task_id": "DSP/333", "completion": "def abs_loss(y_obs, y_hat):\n \"\"\"\n Calculate the absolute loss of the observed data and predicted data.\n \n Parameters\n ------------\n y_obs: an array of observed values\n y_hat: an array of predicted values\n \n Returns\n ------------\n An array of loss values corresponding to the absolute loss for each prediction\n \"\"\"\n ...\n return abs(y_obs - y_hat)"}
{"task_id": "DSP/334", "completion": "bus['postal_code_5'] = bus['postal_code_5'].str.replace('94602', '94102')"}
{"task_id": "DSP/334", "completion": "bus['postal_code_5'] = bus['postal_code_5'].str.replace('94602', '94102')"}
{"task_id": "DSP/335", "completion": "def find_slice(matx):\n ### BEGIN SOLUTION\n return matx[:2, 1:3]\n ### END SOLUTION"}
{"task_id": "DSP/335", "completion": "def find_slice(matx):\n ### BEGIN SOLUTION\n return matx[:2, 1:3]\n ### END SOLUTION"}
{"task_id": "DSP/336", "completion": "def update_slice(matx):\n ### BEGIN SOLUTION\n matx[:2, 1:3] += 1000\n return matx\n ### END SOLUTION"}
{"task_id": "DSP/336", "completion": "def update_slice(matx):\n ### BEGIN SOLUTION\n matx[:2, 1:3] += 1000\n return matx\n ### END SOLUTION"}
{"task_id": "DSP/337", "completion": "def boolean_filter(matx):\n ### BEGIN SOLUTION\n return matx[matx<1.5]\n ### END SOLUTION"}
{"task_id": "DSP/337", "completion": "def boolean_filter(matx):\n ### BEGIN SOLUTION\n return matx[matx<1.5]\n ### END SOLUTION"}
{"task_id": "DSP/338", "completion": "def int_converter(matx):\n ### BEGIN SOLUTION\n return np.array(matx, dtype=np.int)\n ### END SOLUTION"}
{"task_id": "DSP/338", "completion": "def int_converter(matx):\n ### BEGIN SOLUTION\n return np.array(matx, dtype=np.int)\n ### END SOLUTION"}
{"task_id": "DSP/339", "completion": "def selective_replace(matx):\n ### BEGIN SOLUTION\n matx[matx % 2 == 0] = 55\n ### END SOLUTION"}
{"task_id": "DSP/339", "completion": "def selective_replace(matx):\n ### BEGIN SOLUTION\n matx[matx % 2 == 0] = 55\n ### END SOLUTION"}
{"task_id": "DSP/340", "completion": "def row_means(matx):\n ### BEGIN SOLUTION\n return matx.mean(axis = 1)\n ### END SOLUTION"}
{"task_id": "DSP/340", "completion": "def row_means(matx):\n ### BEGIN SOLUTION\n return matx.mean(axis = 1)\n ### END SOLUTION"}
{"task_id": "DSP/341", "completion": "def unique_finder(matx):\n ### BEGIN SOLUTION\n return np.unique(matx)\n ### END SOLUTION"}
{"task_id": "DSP/341", "completion": "def unique_finder(matx):\n ### BEGIN SOLUTION\n return np.unique(matx)\n ### END SOLUTION"}
{"task_id": "DSP/342", "completion": "def first_row_adder(matx):\n ### BEGIN SOLUTION\n return matx + matx[0,:]\n ### END SOLUTION"}
{"task_id": "DSP/342", "completion": "def first_row_adder(matx):\n ### BEGIN SOLUTION\n return matx + matx[0,:]\n ### END SOLUTION"}
{"task_id": "DSP/343", "completion": "mpg_data = pd.read_fwf(\"data/auto-mpg.data\", header = None)\nmpg_data.columns = [\n \"mpg\",\n \"cylinders\",\n \"displacement\",\n \"horsepower\",\n \"weight\",\n \"acceleration\",\n \"model_year\",\n \"origin\",\n \"car_name\"\n]"}
{"task_id": "DSP/343", "completion": "mpg_data = pd.read_fwf(\"data/auto-mpg.data\", header = None)\nmpg_data.columns = [\n \"mpg\",\n \"cylinders\",\n \"displacement\",\n \"horsepower\",\n \"weight\",\n \"acceleration\",\n \"model_year\",\n \"origin\",\n \"car_name\"\n]"}
{"task_id": "DSP/344", "completion": "mpg_data.loc[mpg_data.horsepower == '?', 'horsepower'] = np.nan\nmpg_data.horsepower = mpg_data.horsepower.astype(\"float64\")\nmpg_data.horsepower.unique()"}
{"task_id": "DSP/344", "completion": "mpg_data.loc[mpg_data.horsepower == '?', 'horsepower'] = np.nan\nmpg_data.horsepower = mpg_data.horsepower.astype(\"float64\")\nmpg_data.horsepower.unique()"}
{"task_id": "DSP/345", "completion": "mpg_data.dropna(subset = [\"horsepower\"], inplace = True)\nmpg_data.horsepower.unique()"}
{"task_id": "DSP/345", "completion": "mpg_data.dropna(subset = [\"horsepower\"], inplace = True)\nmpg_data.horsepower.unique()"}
{"task_id": "DSP/346", "completion": "def get_model_names_smallest_cylinders(dataframe):\n \"\"\"\n Returns the names of the cars with the smallest number of cylinders\n \"\"\"\n condition = dataframe.cylinders == dataframe.cylinders.min()\n car_names = dataframe[condition].car_name\n return car_names"}
{"task_id": "DSP/346", "completion": "def get_model_names_smallest_cylinders(dataframe):\n \"\"\"\n Returns the names of the cars with the smallest number of cylinders\n \"\"\"\n condition = dataframe.cylinders == dataframe.cylinders.min()\n car_names = dataframe[condition].car_name\n return car_names"}
{"task_id": "DSP/347", "completion": "def calculate_correlation(dataframe, first_column, second_column):\n \"\"\"\n Calculates and returns the correlation coefficient between the two columns in the dataframe.\n \"\"\"\n correlation = dataframe[first_column].corr(dataframe[second_column])\n return correlation"}
{"task_id": "DSP/347", "completion": "def calculate_correlation(dataframe, first_column, second_column):\n \"\"\"\n Calculates and returns the correlation coefficient between the two columns in the dataframe.\n \"\"\"\n correlation = dataframe[first_column].corr(dataframe[second_column])\n return correlation"}
{"task_id": "DSP/348", "completion": "income_data = pd.read_csv(\"https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data\",\n header = None, sep = r\",\\s\", engine = \"python\")\nincome_data.columns = [\n \"age\",\n \"work_class\",\n \"fnlwgt\",\n \"education\",\n \"education_num\",\n \"marital_status\",\n \"occupation\",\n \"relationship\",\n \"race\",\n \"sex\",\n \"capital_gain\",\n \"capital_loss\",\n \"hours_weekly\",\n \"native_country\",\n \"salary\"\n]\nincome_data.head()"}
{"task_id": "DSP/348", "completion": "income_data = pd.read_csv(\"https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data\",\n header = None, sep = r\",\\s\", engine = \"python\")\nincome_data.columns = [\n \"age\",\n \"work_class\",\n \"fnlwgt\",\n \"education\",\n \"education_num\",\n \"marital_status\",\n \"occupation\",\n \"relationship\",\n \"race\",\n \"sex\",\n \"capital_gain\",\n \"capital_loss\",\n \"hours_weekly\",\n \"native_country\",\n \"salary\"\n]\nincome_data.head()"}
{"task_id": "DSP/349", "completion": "def get_num_people_with_higher_gain(dataframe, threshold_gain):\n return dataframe[dataframe.capital_gain >= threshold_gain].capital_gain.count()"}
{"task_id": "DSP/349", "completion": "def get_num_people_with_higher_gain(dataframe, threshold_gain):\n return dataframe[dataframe.capital_gain >= threshold_gain].capital_gain.count()"}
{"task_id": "DSP/350", "completion": "def most_prominent_marital_status(dataframe):\n status = \"\"\n num_people = 0\n grouped_by_marital_status = dataframe.groupby(\"marital_status\")\n for key, value in grouped_by_marital_status:\n if len(value) > num_people:\n num_people = len(value)\n status = key\n return (status, num_people)"}
{"task_id": "DSP/350", "completion": "def most_prominent_marital_status(dataframe):\n status = \"\"\n num_people = 0\n grouped_by_marital_status = dataframe.groupby(\"marital_status\")\n for key, value in grouped_by_marital_status:\n if len(value) > num_people:\n num_people = len(value)\n status = key\n return (status, num_people)"}
{"task_id": "DSP/351", "completion": "def get_num_people_by_age_category(dataframe):\n young = dataframe[dataframe.age <= 30].age.count()\n middle_aged = dataframe[(dataframe.age > 30) & (dataframe.age <= 60)].age.count()\n old = dataframe[dataframe.age > 60].age.count()\n return young, middle_aged, old\n\nget_num_people_by_age_category(income_data)"}
{"task_id": "DSP/351", "completion": "def get_num_people_by_age_category(dataframe):\n young = dataframe[dataframe.age <= 30].age.count()\n middle_aged = dataframe[(dataframe.age > 30) & (dataframe.age <= 60)].age.count()\n old = dataframe[dataframe.age > 60].age.count()\n return young, middle_aged, old\n\nget_num_people_by_age_category(income_data)"}
{"task_id": "DSP/352", "completion": "def get_second_highest_num_people(dataframe):\n grouped_by_country = dataframe.groupby(\"native_country\")\n count_by_country = {key: len(value) for key, value in grouped_by_country}\n sorted_count_by_country = sorted(count_by_country.items(), key = operator.itemgetter(1))\n country = sorted_count_by_country[-2][0]\n num_people = sorted_count_by_country[-2][1]\n return num_people, country\n\nnum_people, country = get_second_highest_num_people(income_data)\nprint(country)\nprint(num_people)"}
{"task_id": "DSP/352", "completion": "def get_second_highest_num_people(dataframe):\n grouped_by_country = dataframe.groupby(\"native_country\")\n count_by_country = {key: len(value) for key, value in grouped_by_country}\n sorted_count_by_country = sorted(count_by_country.items(), key = operator.itemgetter(1))\n country = sorted_count_by_country[-2][0]\n num_people = sorted_count_by_country[-2][1]\n return num_people, country\n\nnum_people, country = get_second_highest_num_people(income_data)\nprint(country)\nprint(num_people)"}
{"task_id": "DSP/353", "completion": "def get_mean_working_hours_by_income(dataframe):\n result = dataframe.groupby(\"occupation\").hours_weekly.mean()\n sorted_result = result.sort_values(ascending = False)\n return sorted_result"}
{"task_id": "DSP/353", "completion": "def get_mean_working_hours_by_income(dataframe):\n result = dataframe.groupby(\"occupation\").hours_weekly.mean()\n sorted_result = result.sort_values(ascending = False)\n return sorted_result"}
{"task_id": "DSP/354", "completion": "failed_student_times = np.random.uniform(1, 3, 12)\npassed_student_times = np.random.uniform(7, 10, 8)\nall_times = np.concatenate([failed_student_times, passed_student_times])\n\nexam_result = []\nfor student_time in all_times:\n if student_time <= 3:\n exam_result.append(0)\n else:\n exam_result.append(1)\nexam_result = np.array(exam_result)"}
{"task_id": "DSP/354", "completion": "failed_student_times = np.random.uniform(1, 3, 12)\npassed_student_times = np.random.uniform(7, 10, 8)\nall_times = np.concatenate([failed_student_times, passed_student_times])\n\nexam_result = []\nfor student_time in all_times:\n if student_time <= 3:\n exam_result.append(0)\n else:\n exam_result.append(1)\nexam_result = np.array(exam_result)"}
{"task_id": "DSP/355", "completion": "all_times = np.random.uniform(1, 10, 20)\nexam_result = []\nfor student_time in all_times:\n if student_time <= 3:\n exam_result.append(0)\n elif student_time >= 7:\n exam_result.append(1)\n else:\n random_number = np.random.random()\n if random_number >= 0.5:\n exam_result.append(1)\n else:\n exam_result.append(0)\nexam_result = np.array(exam_result)"}
{"task_id": "DSP/355", "completion": "all_times = np.random.uniform(1, 10, 20)\nexam_result = []\nfor student_time in all_times:\n if student_time <= 3:\n exam_result.append(0)\n elif student_time >= 7:\n exam_result.append(1)\n else:\n random_number = np.random.random()\n if random_number >= 0.5:\n exam_result.append(1)\n else:\n exam_result.append(0)\nexam_result = np.array(exam_result)"}
{"task_id": "DSP/356", "completion": "def error_0(x):\n return -np.log(1 - x)\n\ndef error_1(x):\n return -np.log(x)"}
{"task_id": "DSP/356", "completion": "def error_0(x):\n return -np.log(1 - x)\n\ndef error_1(x):\n return -np.log(x)"}
{"task_id": "DSP/357", "completion": "def naturals(val):\n sum = 0;\n for i in range(val):\n if 3 * i < val:\n sum += (3*i) \n if 5 * i < val:\n sum += (5*i)\n return sum"}
{"task_id": "DSP/357", "completion": "def naturals(val):\n sum = 0;\n for i in range(val):\n if 3 * i < val:\n sum += (3*i) \n if 5 * i < val:\n sum += (5*i)\n return sum"}
{"task_id": "DSP/358", "completion": "def sdiff(val):\n sum2 = 0\n sum3 = 0\n for i in range(val):\n sum2 += i**2\n sum3 += i\n\n sum2 -= sum3\n return sum2"}
{"task_id": "DSP/358", "completion": "def sdiff(val):\n sum2 = 0\n sum3 = 0\n for i in range(val):\n sum2 += i**2\n sum3 += i\n\n sum2 -= sum3\n return sum2"}
{"task_id": "DSP/359", "completion": "def vector_sum(x, y):\n for i in range(len(x)) :\n x[i] = x[i] + y[i]\n \n return x"}
{"task_id": "DSP/359", "completion": "def vector_sum(x, y):\n for i in range(len(x)) :\n x[i] = x[i] + y[i]\n \n return x"}
{"task_id": "DSP/360", "completion": "def vector_diff(x, y):\n for i in range(len(x)) :\n x[i] = math.fabs(x[i] - y[i])\n return x"}
{"task_id": "DSP/360", "completion": "def vector_diff(x, y):\n for i in range(len(x)) :\n x[i] = math.fabs(x[i] - y[i])\n return x"}
{"task_id": "DSP/361", "completion": "def vector_scalar_mul(a, x):\n for i in range(len(x)) :\n x[i] *= a\n \n return x"}
{"task_id": "DSP/361", "completion": "def vector_scalar_mul(a, x):\n for i in range(len(x)) :\n x[i] *= a\n \n return x"}
{"task_id": "DSP/362", "completion": "def vector_dot(x, y):\n dot = 0\n for i in range(len(x)) :\n dot += x[i] * y[i]\n\n return dot"}
{"task_id": "DSP/362", "completion": "def vector_dot(x, y):\n dot = 0\n for i in range(len(x)) :\n dot += x[i] * y[i]\n\n return dot"}
{"task_id": "DSP/363", "completion": "def L1(x):\n norm = 0\n for i in range(len(x)) :\n norm += math.fabs(x[i])\n \n return norm"}
{"task_id": "DSP/363", "completion": "def L1(x):\n norm = 0\n for i in range(len(x)) :\n norm += math.fabs(x[i])\n \n return norm"}
{"task_id": "DSP/364", "completion": "def L2(x):\n l2 = 0\n for i in range(len(x)) :\n l2 += x[i]**2 \n \n return math.sqrt(l2)"}
{"task_id": "DSP/364", "completion": "def L2(x):\n l2 = 0\n for i in range(len(x)) :\n l2 += x[i]**2 \n \n return math.sqrt(l2)"}
{"task_id": "DSP/365", "completion": "def mse(x, y):\n for i in range(len(x)):\n x[i] -= y[i]\n x[i] = x[i]**2\n \n return math.fsum(x)/ len(x)"}
{"task_id": "DSP/365", "completion": "def mse(x, y):\n for i in range(len(x)):\n x[i] -= y[i]\n x[i] = x[i]**2\n \n return math.fsum(x)/ len(x)"}
{"task_id": "DSP/366", "completion": "def mean(x):\n return math.fsum(x) / len(x)"}
{"task_id": "DSP/366", "completion": "def mean(x):\n return math.fsum(x) / len(x)"}
{"task_id": "DSP/367", "completion": "def var(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n \n return math.fsum(x) / len(x)"}
{"task_id": "DSP/367", "completion": "def var(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n \n return math.fsum(x) / len(x)"}
{"task_id": "DSP/368", "completion": "def std(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n\n return math.sqrt(math.fsum(x) / len(x))"}
{"task_id": "DSP/368", "completion": "def std(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n\n return math.sqrt(math.fsum(x) / len(x))"}
{"task_id": "DSP/369", "completion": "def uniform2(mu, sigma, size=1):\n \"\"\"Return uniform random variates with mean mu and standard dev sigma.\n \"\"\"\n a = mu - np.sqrt(3*sigma**2)\n b = mu + np.sqrt(3*sigma**2)\n var = np.random.uniform(a,b,size)\n return var"}
{"task_id": "DSP/369", "completion": "def uniform2(mu, sigma, size=1):\n \"\"\"Return uniform random variates with mean mu and standard dev sigma.\n \"\"\"\n a = mu - np.sqrt(3*sigma**2)\n b = mu + np.sqrt(3*sigma**2)\n var = np.random.uniform(a,b,size)\n return var"}
{"task_id": "DSP/370", "completion": "def log_normal(mu, sigma, size=1):\n \"\"\"Return an array of size log-normal random variates.\"\"\"\n arr = np.random.normal(mu, sigma, size=size)\n arr = np.exp(arr)\n return arr"}
{"task_id": "DSP/370", "completion": "def log_normal(mu, sigma, size=1):\n \"\"\"Return an array of size log-normal random variates.\"\"\"\n arr = np.random.normal(mu, sigma, size=size)\n arr = np.exp(arr)\n return arr"}
{"task_id": "DSP/371", "completion": "def fair(data):\n h = 0\n\n if 'H' not in data:\n return 0.0\n \n for ele in data:\n if ele == 'H':\n h += 1\n\n return h/len(data)"}
{"task_id": "DSP/371", "completion": "def fair(data):\n h = 0\n\n if 'H' not in data:\n return 0.0\n \n for ele in data:\n if ele == 'H':\n h += 1\n\n return h/len(data)"}
{"task_id": "DSP/372", "completion": "def bootstrap_data(data):\n boots = np.random.choice(data,len(data))\n return boots"}
{"task_id": "DSP/372", "completion": "def bootstrap_data(data):\n boots = np.random.choice(data,len(data))\n return boots"}
{"task_id": "DSP/373", "completion": "def bootstrap_function(data, f, n):\n arr = []\n for i in range(n):\n arr.append(f(bootstrap_data(data)))\n return np.array(arr)"}
{"task_id": "DSP/373", "completion": "def bootstrap_function(data, f, n):\n arr = []\n for i in range(n):\n arr.append(f(bootstrap_data(data)))\n return np.array(arr)"}
{"task_id": "DSP/374", "completion": "def vector_sum(x, y):\n for i in range(len(x)) :\n x[i] = x[i] + y[i]\n \n return x"}
{"task_id": "DSP/374", "completion": "def vector_sum(x, y):\n for i in range(len(x)) :\n x[i] = x[i] + y[i]\n \n return x"}
{"task_id": "DSP/375", "completion": "def vector_diff(x, y):\n for i in range(len(x)) :\n x[i] = math.fabs(x[i] - y[i])\n return x"}
{"task_id": "DSP/375", "completion": "def vector_diff(x, y):\n for i in range(len(x)) :\n x[i] = math.fabs(x[i] - y[i])\n return x"}
{"task_id": "DSP/376", "completion": "def vector_scalar_mul(a, x):\n for i in range(len(x)) :\n x[i] *= a\n \n return x"}
{"task_id": "DSP/376", "completion": "def vector_scalar_mul(a, x):\n for i in range(len(x)) :\n x[i] *= a\n \n return x"}
{"task_id": "DSP/377", "completion": "def vector_dot(x, y):\n dot = 0\n for i in range(len(x)) :\n dot += x[i] * y[i]\n\n return dot"}
{"task_id": "DSP/377", "completion": "def vector_dot(x, y):\n dot = 0\n for i in range(len(x)) :\n dot += x[i] * y[i]\n\n return dot"}
{"task_id": "DSP/378", "completion": "def L1(x):\n norm = 0\n for i in range(len(x)) :\n norm += math.fabs(x[i])\n \n return norm"}
{"task_id": "DSP/378", "completion": "def L1(x):\n norm = 0\n for i in range(len(x)) :\n norm += math.fabs(x[i])\n \n return norm"}
{"task_id": "DSP/379", "completion": "def L2(x):\n l2 = 0\n for i in range(len(x)) :\n l2 += x[i]**2 \n \n return math.sqrt(l2)"}
{"task_id": "DSP/379", "completion": "def L2(x):\n l2 = 0\n for i in range(len(x)) :\n l2 += x[i]**2 \n \n return math.sqrt(l2)"}
{"task_id": "DSP/380", "completion": "def mse(x, y):\n for i in range(len(x)):\n x[i] -= y[i]\n x[i] = x[i]**2\n \n return math.fsum(x)/ len(x)"}
{"task_id": "DSP/380", "completion": "def mse(x, y):\n for i in range(len(x)):\n x[i] -= y[i]\n x[i] = x[i]**2\n \n return math.fsum(x)/ len(x)"}
{"task_id": "DSP/381", "completion": "def mean(x):\n return math.fsum(x) / len(x)"}
{"task_id": "DSP/381", "completion": "def mean(x):\n return math.fsum(x) / len(x)"}
{"task_id": "DSP/382", "completion": "def var(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n \n return math.fsum(x) / len(x)"}
{"task_id": "DSP/382", "completion": "def var(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n \n return math.fsum(x) / len(x)"}
{"task_id": "DSP/383", "completion": "def std(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n\n return math.sqrt(math.fsum(x) / len(x))"}
{"task_id": "DSP/383", "completion": "def std(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n\n return math.sqrt(math.fsum(x) / len(x))"}
{"task_id": "DSP/384", "completion": "def vector_sum(x, y):\n for i in range(len(x)) :\n x[i] = x[i] + y[i]\n \n return x"}
{"task_id": "DSP/384", "completion": "def vector_sum(x, y):\n for i in range(len(x)) :\n x[i] = x[i] + y[i]\n \n return x"}
{"task_id": "DSP/385", "completion": "def vector_diff(x, y):\n for i in range(len(x)) :\n x[i] = math.fabs(x[i] - y[i])\n return x"}
{"task_id": "DSP/385", "completion": "def vector_diff(x, y):\n for i in range(len(x)) :\n x[i] = math.fabs(x[i] - y[i])\n return x"}
{"task_id": "DSP/386", "completion": "def vector_scalar_mul(a, x):\n for i in range(len(x)) :\n x[i] *= a\n \n return x"}
{"task_id": "DSP/386", "completion": "def vector_scalar_mul(a, x):\n for i in range(len(x)) :\n x[i] *= a\n \n return x"}
{"task_id": "DSP/387", "completion": "def vector_dot(x, y):\n dot = 0\n for i in range(len(x)) :\n dot += x[i] * y[i]\n\n return dot"}
{"task_id": "DSP/387", "completion": "def vector_dot(x, y):\n dot = 0\n for i in range(len(x)) :\n dot += x[i] * y[i]\n\n return dot"}
{"task_id": "DSP/388", "completion": "def L1(x):\n norm = 0\n for i in range(len(x)) :\n norm += math.fabs(x[i])\n \n return norm"}
{"task_id": "DSP/388", "completion": "def L1(x):\n norm = 0\n for i in range(len(x)) :\n norm += math.fabs(x[i])\n \n return norm"}
{"task_id": "DSP/389", "completion": "def L2(x):\n l2 = 0\n for i in range(len(x)) :\n l2 += x[i]**2 \n \n return math.sqrt(l2)"}
{"task_id": "DSP/389", "completion": "def L2(x):\n l2 = 0\n for i in range(len(x)) :\n l2 += x[i]**2 \n \n return math.sqrt(l2)"}
{"task_id": "DSP/390", "completion": "def mse(x, y):\n for i in range(len(x)):\n x[i] -= y[i]\n x[i] = x[i]**2\n \n return math.fsum(x)/ len(x)"}
{"task_id": "DSP/390", "completion": "def mse(x, y):\n for i in range(len(x)):\n x[i] -= y[i]\n x[i] = x[i]**2\n \n return math.fsum(x)/ len(x)"}
{"task_id": "DSP/391", "completion": "def mean(x):\n return math.fsum(x) / len(x)"}
{"task_id": "DSP/391", "completion": "def mean(x):\n return math.fsum(x) / len(x)"}
{"task_id": "DSP/392", "completion": "def var(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n \n return math.fsum(x) / len(x)"}
{"task_id": "DSP/392", "completion": "def var(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n \n return math.fsum(x) / len(x)"}
{"task_id": "DSP/393", "completion": "def std(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n\n return math.sqrt(math.fsum(x) / len(x))"}
{"task_id": "DSP/393", "completion": "def std(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n\n return math.sqrt(math.fsum(x) / len(x))"}
{"task_id": "DSP/394", "completion": "def vector_sum(x, y):\n for i in range(len(x)) :\n x[i] = x[i] + y[i]\n \n return x"}
{"task_id": "DSP/394", "completion": "def vector_sum(x, y):\n for i in range(len(x)) :\n x[i] = x[i] + y[i]\n \n return x"}
{"task_id": "DSP/395", "completion": "def vector_diff(x, y):\n for i in range(len(x)) :\n x[i] = math.fabs(x[i] - y[i])\n return x"}
{"task_id": "DSP/395", "completion": "def vector_diff(x, y):\n for i in range(len(x)) :\n x[i] = math.fabs(x[i] - y[i])\n return x"}
{"task_id": "DSP/396", "completion": "def vector_scalar_mul(a, x):\n for i in range(len(x)) :\n x[i] *= a\n \n return x"}
{"task_id": "DSP/396", "completion": "def vector_scalar_mul(a, x):\n for i in range(len(x)) :\n x[i] *= a\n \n return x"}
{"task_id": "DSP/397", "completion": "def vector_dot(x, y):\n dot = 0\n for i in range(len(x)) :\n dot += x[i] * y[i]\n\n return dot"}
{"task_id": "DSP/397", "completion": "def vector_dot(x, y):\n dot = 0\n for i in range(len(x)) :\n dot += x[i] * y[i]\n\n return dot"}
{"task_id": "DSP/398", "completion": "def L1(x):\n norm = 0\n for i in range(len(x)) :\n norm += math.fabs(x[i])\n \n return norm"}
{"task_id": "DSP/398", "completion": "def L1(x):\n norm = 0\n for i in range(len(x)) :\n norm += math.fabs(x[i])\n \n return norm"}
{"task_id": "DSP/399", "completion": "def L2(x):\n l2 = 0\n for i in range(len(x)) :\n l2 += x[i]**2 \n \n return math.sqrt(l2)"}
{"task_id": "DSP/399", "completion": "def L2(x):\n l2 = 0\n for i in range(len(x)) :\n l2 += x[i]**2 \n \n return math.sqrt(l2)"}
{"task_id": "DSP/400", "completion": "def mse(x, y):\n for i in range(len(x)):\n x[i] -= y[i]\n x[i] = x[i]**2\n \n return math.fsum(x)/ len(x)"}
{"task_id": "DSP/400", "completion": "def mse(x, y):\n for i in range(len(x)):\n x[i] -= y[i]\n x[i] = x[i]**2\n \n return math.fsum(x)/ len(x)"}
{"task_id": "DSP/401", "completion": "def mean(x):\n return math.fsum(x) / len(x)"}
{"task_id": "DSP/401", "completion": "def mean(x):\n return math.fsum(x) / len(x)"}
{"task_id": "DSP/402", "completion": "def var(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n \n return math.fsum(x) / len(x)"}
{"task_id": "DSP/402", "completion": "def var(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n \n return math.fsum(x) / len(x)"}
{"task_id": "DSP/403", "completion": "def std(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n\n return math.sqrt(math.fsum(x) / len(x))"}
{"task_id": "DSP/403", "completion": "def std(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n\n return math.sqrt(math.fsum(x) / len(x))"}
{"task_id": "DSP/404", "completion": "def vector_sum(x, y):\n for i in range(len(x)) :\n x[i] = x[i] + y[i]\n \n return x"}
{"task_id": "DSP/404", "completion": "def vector_sum(x, y):\n for i in range(len(x)) :\n x[i] = x[i] + y[i]\n \n return x"}
{"task_id": "DSP/405", "completion": "def vector_diff(x, y):\n for i in range(len(x)) :\n x[i] = math.fabs(x[i] - y[i])\n return x"}
{"task_id": "DSP/405", "completion": "def vector_diff(x, y):\n for i in range(len(x)) :\n x[i] = math.fabs(x[i] - y[i])\n return x"}
{"task_id": "DSP/406", "completion": "def vector_scalar_mul(a, x):\n for i in range(len(x)) :\n x[i] *= a\n \n return x"}
{"task_id": "DSP/406", "completion": "def vector_scalar_mul(a, x):\n for i in range(len(x)) :\n x[i] *= a\n \n return x"}
{"task_id": "DSP/407", "completion": "def vector_dot(x, y):\n dot = 0\n for i in range(len(x)) :\n dot += x[i] * y[i]\n\n return dot"}
{"task_id": "DSP/407", "completion": "def vector_dot(x, y):\n dot = 0\n for i in range(len(x)) :\n dot += x[i] * y[i]\n\n return dot"}
{"task_id": "DSP/408", "completion": "def L1(x):\n norm = 0\n for i in range(len(x)) :\n norm += math.fabs(x[i])\n \n return norm"}
{"task_id": "DSP/408", "completion": "def L1(x):\n norm = 0\n for i in range(len(x)) :\n norm += math.fabs(x[i])\n \n return norm"}
{"task_id": "DSP/409", "completion": "def L2(x):\n l2 = 0\n for i in range(len(x)) :\n l2 += x[i]**2 \n \n return math.sqrt(l2)"}
{"task_id": "DSP/409", "completion": "def L2(x):\n l2 = 0\n for i in range(len(x)) :\n l2 += x[i]**2 \n \n return math.sqrt(l2)"}
{"task_id": "DSP/410", "completion": "def mse(x, y):\n for i in range(len(x)):\n x[i] -= y[i]\n x[i] = x[i]**2\n \n return math.fsum(x)/ len(x)"}
{"task_id": "DSP/410", "completion": "def mse(x, y):\n for i in range(len(x)):\n x[i] -= y[i]\n x[i] = x[i]**2\n \n return math.fsum(x)/ len(x)"}
{"task_id": "DSP/411", "completion": "def mean(x):\n return math.fsum(x) / len(x)"}
{"task_id": "DSP/411", "completion": "def mean(x):\n return math.fsum(x) / len(x)"}
{"task_id": "DSP/412", "completion": "def var(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n \n return math.fsum(x) / len(x)"}
{"task_id": "DSP/412", "completion": "def var(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n \n return math.fsum(x) / len(x)"}
{"task_id": "DSP/413", "completion": "def std(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n\n return math.sqrt(math.fsum(x) / len(x))"}
{"task_id": "DSP/413", "completion": "def std(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n\n return math.sqrt(math.fsum(x) / len(x))"}
{"task_id": "DSP/414", "completion": "def hat(x,a=5.0,b=1.0):\n return -a* x*x + b*x**4"}
{"task_id": "DSP/414", "completion": "def hat(x,a=5.0,b=1.0):\n return -a* x*x + b*x**4"}
{"task_id": "DSP/415", "completion": "def uniform2(mu, sigma, size=1):\n \"\"\"Return uniform random variates with mean mu and standard dev sigma.\n \"\"\"\n a = mu - np.sqrt(3*sigma**2)\n b = mu + np.sqrt(3*sigma**2)\n var = np.random.uniform(a,b,size)\n return var"}
{"task_id": "DSP/415", "completion": "def uniform2(mu, sigma, size=1):\n \"\"\"Return uniform random variates with mean mu and standard dev sigma.\n \"\"\"\n a = mu - np.sqrt(3*sigma**2)\n b = mu + np.sqrt(3*sigma**2)\n var = np.random.uniform(a,b,size)\n return var"}
{"task_id": "DSP/416", "completion": "def fair(data):\n h = 0\n\n if 'H' not in data:\n return 0.0\n \n for ele in data:\n if ele == 'H':\n h += 1\n\n return h/len(data)"}
{"task_id": "DSP/416", "completion": "def fair(data):\n h = 0\n\n if 'H' not in data:\n return 0.0\n \n for ele in data:\n if ele == 'H':\n h += 1\n\n return h/len(data)"}
{"task_id": "DSP/417", "completion": "def bootstrap_data(data):\n boots = np.random.choice(data,len(data))\n return boots"}
{"task_id": "DSP/417", "completion": "def bootstrap_data(data):\n boots = np.random.choice(data,len(data))\n return boots"}
{"task_id": "DSP/418", "completion": "def bootstrap_function(data, f, n):\n arr = []\n for i in range(n):\n arr.append(f(bootstrap_data(data)))\n return np.array(arr)"}
{"task_id": "DSP/418", "completion": "def bootstrap_function(data, f, n):\n arr = []\n for i in range(n):\n arr.append(f(bootstrap_data(data)))\n return np.array(arr)"}
{"task_id": "DSP/419", "completion": "def log_normal(mu, sigma, size=1):\n \"\"\"Return an array of size log-normal random variates.\"\"\"\n arr = np.random.normal(mu, sigma, size=size)\n arr = np.exp(arr)\n return arr"}
{"task_id": "DSP/419", "completion": "def log_normal(mu, sigma, size=1):\n \"\"\"Return an array of size log-normal random variates.\"\"\"\n arr = np.random.normal(mu, sigma, size=size)\n arr = np.exp(arr)\n return arr"}
{"task_id": "DSP/420", "completion": "def vector_sum(x, y):\n for i in range(len(x)) :\n x[i] = x[i] + y[i]\n \n return x"}
{"task_id": "DSP/420", "completion": "def vector_sum(x, y):\n for i in range(len(x)) :\n x[i] = x[i] + y[i]\n \n return x"}
{"task_id": "DSP/421", "completion": "def vector_diff(x, y):\n for i in range(len(x)) :\n x[i] = math.fabs(x[i] - y[i])\n return x"}
{"task_id": "DSP/421", "completion": "def vector_diff(x, y):\n for i in range(len(x)) :\n x[i] = math.fabs(x[i] - y[i])\n return x"}
{"task_id": "DSP/422", "completion": "def vector_scalar_mul(a, x):\n for i in range(len(x)) :\n x[i] *= a\n \n return x"}
{"task_id": "DSP/422", "completion": "def vector_scalar_mul(a, x):\n for i in range(len(x)) :\n x[i] *= a\n \n return x"}
{"task_id": "DSP/423", "completion": "def vector_dot(x, y):\n dot = 0\n for i in range(len(x)) :\n dot += x[i] * y[i]\n\n return dot"}
{"task_id": "DSP/423", "completion": "def vector_dot(x, y):\n dot = 0\n for i in range(len(x)) :\n dot += x[i] * y[i]\n\n return dot"}
{"task_id": "DSP/424", "completion": "def L1(x):\n norm = 0\n for i in range(len(x)) :\n norm += math.fabs(x[i])\n \n return norm"}
{"task_id": "DSP/424", "completion": "def L1(x):\n norm = 0\n for i in range(len(x)) :\n norm += math.fabs(x[i])\n \n return norm"}
{"task_id": "DSP/425", "completion": "def L2(x):\n l2 = 0\n for i in range(len(x)) :\n l2 += x[i]**2 \n \n return math.sqrt(l2)"}
{"task_id": "DSP/425", "completion": "def L2(x):\n l2 = 0\n for i in range(len(x)) :\n l2 += x[i]**2 \n \n return math.sqrt(l2)"}
{"task_id": "DSP/426", "completion": "def mse(x, y):\n for i in range(len(x)):\n x[i] -= y[i]\n x[i] = x[i]**2\n \n return math.fsum(x)/ len(x)"}
{"task_id": "DSP/426", "completion": "def mse(x, y):\n for i in range(len(x)):\n x[i] -= y[i]\n x[i] = x[i]**2\n \n return math.fsum(x)/ len(x)"}
{"task_id": "DSP/427", "completion": "def mean(x):\n return math.fsum(x) / len(x)"}
{"task_id": "DSP/427", "completion": "def mean(x):\n return math.fsum(x) / len(x)"}
{"task_id": "DSP/428", "completion": "def var(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n \n return math.fsum(x) / len(x)"}
{"task_id": "DSP/428", "completion": "def var(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n \n return math.fsum(x) / len(x)"}
{"task_id": "DSP/429", "completion": "def std(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n\n return math.sqrt(math.fsum(x) / len(x))"}
{"task_id": "DSP/429", "completion": "def std(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n\n return math.sqrt(math.fsum(x) / len(x))"}
{"task_id": "DSP/430", "completion": "def sdiff(val):\n sum2 = 0\n sum3 = 0\n for i in range(val):\n sum2 += i**2\n sum3 += i\n\n sum2 -= sum3\n return sum2"}
{"task_id": "DSP/430", "completion": "def sdiff(val):\n sum2 = 0\n sum3 = 0\n for i in range(val):\n sum2 += i**2\n sum3 += i\n\n sum2 -= sum3\n return sum2"}
{"task_id": "DSP/431", "completion": "sim1 = np.random.poisson(t1_avg, n)\nsim2 = np.random.poisson(t2_avg, n)"}
{"task_id": "DSP/431", "completion": "sim1 = np.random.poisson(t1_avg, n)\nsim2 = np.random.poisson(t2_avg, n)"}
{"task_id": "DSP/432", "completion": "spread = sim2 - sim1"}
{"task_id": "DSP/432", "completion": "spread = sim2 - sim1"}
{"task_id": "DSP/433", "completion": "results = wiener(1.0, 1000)\nt = list(results)[0]\nW = list(results)[1]\nprint(len(t), len(W))"}
{"task_id": "DSP/433", "completion": "results = wiener(1.0, 1000)\nt = list(results)[0]\nW = list(results)[1]\nprint(len(t), len(W))"}
{"task_id": "DSP/434", "completion": "def same_digits(x, y):\n a = list(x)\n b = list(y)\n \n if len(a) != len(b):\n return False\n \n for i in range(len(a)):\n if a[i] not in b:\n return False\n \n return True"}
{"task_id": "DSP/434", "completion": "def same_digits(x, y):\n a = list(x)\n b = list(y)\n \n if len(a) != len(b):\n return False\n \n for i in range(len(a)):\n if a[i] not in b:\n return False\n \n return True"}
{"task_id": "DSP/435", "completion": "def fair(data):\n h = 0\n\n if 'H' not in data:\n return 0.0\n \n for ele in data:\n if ele == 'H':\n h += 1\n\n return h/len(data)"}
{"task_id": "DSP/435", "completion": "def fair(data):\n h = 0\n\n if 'H' not in data:\n return 0.0\n \n for ele in data:\n if ele == 'H':\n h += 1\n\n return h/len(data)"}
{"task_id": "DSP/436", "completion": "def bootstrap_data(data):\n boots = np.random.choice(data,len(data))\n return boots"}
{"task_id": "DSP/436", "completion": "def bootstrap_data(data):\n boots = np.random.choice(data,len(data))\n return boots"}
{"task_id": "DSP/437", "completion": "def bootstrap_function(data, f, n):\n arr = []\n for i in range(n):\n arr.append(f(bootstrap_data(data)))\n return np.array(arr)"}
{"task_id": "DSP/437", "completion": "def bootstrap_function(data, f, n):\n arr = []\n for i in range(n):\n arr.append(f(bootstrap_data(data)))\n return np.array(arr)"}
{"task_id": "DSP/438", "completion": "def log_normal(mu, sigma, size=1):\n \"\"\"Return an array of size log-normal random variates.\"\"\"\n arr = np.random.normal(mu, sigma, size=size)\n arr = np.exp(arr)\n return arr"}
{"task_id": "DSP/438", "completion": "def log_normal(mu, sigma, size=1):\n \"\"\"Return an array of size log-normal random variates.\"\"\"\n arr = np.random.normal(mu, sigma, size=size)\n arr = np.exp(arr)\n return arr"}
{"task_id": "DSP/439", "completion": "def same_digits(x, y):\n a = list(x)\n b = list(y)\n \n if len(a) != len(b):\n return False\n \n for i in range(len(a)):\n if a[i] not in b:\n return False\n \n return True"}
{"task_id": "DSP/439", "completion": "def same_digits(x, y):\n a = list(x)\n b = list(y)\n \n if len(a) != len(b):\n return False\n \n for i in range(len(a)):\n if a[i] not in b:\n return False\n \n return True"}
{"task_id": "DSP/440", "completion": "def uniform2(mu, sigma, size=1):\n \"\"\"Return uniform random variates with mean mu and standard dev sigma.\n \"\"\"\n a = mu - np.sqrt(3*sigma**2)\n b = mu + np.sqrt(3*sigma**2)\n var = np.random.uniform(a,b,size)\n return var"}
{"task_id": "DSP/440", "completion": "def uniform2(mu, sigma, size=1):\n \"\"\"Return uniform random variates with mean mu and standard dev sigma.\n \"\"\"\n a = mu - np.sqrt(3*sigma**2)\n b = mu + np.sqrt(3*sigma**2)\n var = np.random.uniform(a,b,size)\n return var"}
{"task_id": "DSP/441", "completion": "results = wiener(1.0, 1000)\nt = list(results)[0]\nW = list(results)[1]\nprint(len(t), len(W))"}
{"task_id": "DSP/441", "completion": "results = wiener(1.0, 1000)\nt = list(results)[0]\nW = list(results)[1]\nprint(len(t), len(W))"}
{"task_id": "DSP/442", "completion": "def vector_sum(x, y):\n for i in range(len(x)) :\n x[i] = x[i] + y[i]\n \n return x"}
{"task_id": "DSP/442", "completion": "def vector_sum(x, y):\n for i in range(len(x)) :\n x[i] = x[i] + y[i]\n \n return x"}
{"task_id": "DSP/443", "completion": "def vector_diff(x, y):\n for i in range(len(x)) :\n x[i] = math.fabs(x[i] - y[i])\n return x"}
{"task_id": "DSP/443", "completion": "def vector_diff(x, y):\n for i in range(len(x)) :\n x[i] = math.fabs(x[i] - y[i])\n return x"}
{"task_id": "DSP/444", "completion": "def vector_scalar_mul(a, x):\n for i in range(len(x)) :\n x[i] *= a\n \n return x"}
{"task_id": "DSP/444", "completion": "def vector_scalar_mul(a, x):\n for i in range(len(x)) :\n x[i] *= a\n \n return x"}
{"task_id": "DSP/445", "completion": "def vector_dot(x, y):\n dot = 0\n for i in range(len(x)) :\n dot += x[i] * y[i]\n\n return dot"}
{"task_id": "DSP/445", "completion": "def vector_dot(x, y):\n dot = 0\n for i in range(len(x)) :\n dot += x[i] * y[i]\n\n return dot"}
{"task_id": "DSP/446", "completion": "def L1(x):\n norm = 0\n for i in range(len(x)) :\n norm += math.fabs(x[i])\n \n return norm"}
{"task_id": "DSP/446", "completion": "def L1(x):\n norm = 0\n for i in range(len(x)) :\n norm += math.fabs(x[i])\n \n return norm"}
{"task_id": "DSP/447", "completion": "def L2(x):\n l2 = 0\n for i in range(len(x)) :\n l2 += x[i]**2 \n \n return math.sqrt(l2)"}
{"task_id": "DSP/447", "completion": "def L2(x):\n l2 = 0\n for i in range(len(x)) :\n l2 += x[i]**2 \n \n return math.sqrt(l2)"}
{"task_id": "DSP/448", "completion": "def mse(x, y):\n for i in range(len(x)):\n x[i] -= y[i]\n x[i] = x[i]**2\n \n return math.fsum(x)/ len(x)"}
{"task_id": "DSP/448", "completion": "def mse(x, y):\n for i in range(len(x)):\n x[i] -= y[i]\n x[i] = x[i]**2\n \n return math.fsum(x)/ len(x)"}
{"task_id": "DSP/449", "completion": "def mean(x):\n return math.fsum(x) / len(x)"}
{"task_id": "DSP/449", "completion": "def mean(x):\n return math.fsum(x) / len(x)"}
{"task_id": "DSP/450", "completion": "def var(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n \n return math.fsum(x) / len(x)"}
{"task_id": "DSP/450", "completion": "def var(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n \n return math.fsum(x) / len(x)"}
{"task_id": "DSP/451", "completion": "def std(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n\n return math.sqrt(math.fsum(x) / len(x))"}
{"task_id": "DSP/451", "completion": "def std(x):\n mean = math.fsum(x) / len(x) \n for i in range(len(x)):\n x[i] -= mean\n x[i] = x[i]**2\n\n return math.sqrt(math.fsum(x) / len(x))"}
{"task_id": "DSP/452", "completion": "sim1 = np.random.poisson(t1_avg, n)\nsim2 = np.random.poisson(t2_avg, n)"}
{"task_id": "DSP/452", "completion": "sim1 = np.random.poisson(t1_avg, n)\nsim2 = np.random.poisson(t2_avg, n)"}
{"task_id": "DSP/453", "completion": "spread = sim2 - sim1"}
{"task_id": "DSP/453", "completion": "spread = sim2 - sim1"}
{"task_id": "DSP/454", "completion": "def hat(x,a=5.0,b=1.0):\n return -a* x*x + b*x**4"}
{"task_id": "DSP/454", "completion": "def hat(x,a=5.0,b=1.0):\n return -a* x*x + b*x**4"}
{"task_id": "DSP/455", "completion": "results = wiener(1.0, 1000)\nt = list(results)[0]\nW = list(results)[1]\nprint(len(t), len(W))"}
{"task_id": "DSP/455", "completion": "results = wiener(1.0, 1000)\nt = list(results)[0]\nW = list(results)[1]\nprint(len(t), len(W))"}
{"task_id": "DSP/456", "completion": "def same_digits(x, y):\n a = list(x)\n b = list(y)\n \n if len(a) != len(b):\n return False\n \n for i in range(len(a)):\n if a[i] not in b:\n return False\n \n return True"}
{"task_id": "DSP/456", "completion": "def same_digits(x, y):\n a = list(x)\n b = list(y)\n \n if len(a) != len(b):\n return False\n \n for i in range(len(a)):\n if a[i] not in b:\n return False\n \n return True"}
{"task_id": "DSP/457", "completion": "A0 = ratings.assign(rating_100 = lambda x: (x.rating - 1)*25)\n### END SOLUTION"}
{"task_id": "DSP/457", "completion": "A0 = ratings.assign(rating_100 = lambda x: (x.rating - 1)*25)\n### END SOLUTION"}
{"task_id": "DSP/458", "completion": "A4 = movies.loc[1, 'title']\n### END SOLUTION"}
{"task_id": "DSP/458", "completion": "A4 = movies.loc[1, 'title']\n### END SOLUTION"}
{"task_id": "DSP/459", "completion": "import numpy as np\n\ndef create_array():\n ### BEGIN SOLUTION\n result = np.arange(16)[1:].reshape((3,5)).T\n ### END SOLUTION\n return result"}
{"task_id": "DSP/459", "completion": "import numpy as np\n\ndef create_array():\n ### BEGIN SOLUTION\n result = np.arange(16)[1:].reshape((3,5)).T\n ### END SOLUTION\n return result"}
{"task_id": "DSP/460", "completion": "import numpy as np\n\ndef new_array_second_and_fourth(original):\n ### BEGIN SOLUTION\n if original.shape[0] < 4:\n result = None\n else:\n result = original[[1,3],:]\n ### END SOLUTION\n return result"}
{"task_id": "DSP/460", "completion": "import numpy as np\n\ndef new_array_second_and_fourth(original):\n ### BEGIN SOLUTION\n if original.shape[0] < 4:\n result = None\n else:\n result = original[[1,3],:]\n ### END SOLUTION\n return result"}
{"task_id": "DSP/461", "completion": "import numpy as np\n\ndef new_array_section(original):\n ### BEGIN SOLUTION\n if len(original.shape) == 1:\n result = None\n else:\n if original.shape[0] < 4 or original.shape[1] < 3:\n result = None\n else:\n result = original[1:4,0:3]\n\n ### END SOLUTION\n return result"}
{"task_id": "DSP/461", "completion": "import numpy as np\n\ndef new_array_section(original):\n ### BEGIN SOLUTION\n if len(original.shape) == 1:\n result = None\n else:\n if original.shape[0] < 4 or original.shape[1] < 3:\n result = None\n else:\n result = original[1:4,0:3]\n\n ### END SOLUTION\n return result"}
{"task_id": "DSP/462", "completion": "import numpy as np\n\ndef new_array_values(original):\n ### BEGIN SOLUTION\n if len(original.shape) == 1:\n result = np.array([])\n else:\n result = original[original <= 11]\n result = result[result >= 3]\n \n ### END SOLUTION\n return result"}
{"task_id": "DSP/462", "completion": "import numpy as np\n\ndef new_array_values(original):\n ### BEGIN SOLUTION\n if len(original.shape) == 1:\n result = np.array([])\n else:\n result = original[original <= 11]\n result = result[result >= 3]\n \n ### END SOLUTION\n return result"}
{"task_id": "DSP/463", "completion": "import numpy as np\n\ndef array_divide():\n ### BEGIN SOLUTION\n a = np.arange(25).reshape(5,5)\n a = a.astype(float)\n for i in range(5)[1:]:\n a[i,:] = a[i,:] / (5.0 * i) \n result = a\n ### END SOLUTION\n return result"}
{"task_id": "DSP/463", "completion": "import numpy as np\n\ndef array_divide():\n ### BEGIN SOLUTION\n a = np.arange(25).reshape(5,5)\n a = a.astype(float)\n for i in range(5)[1:]:\n a[i,:] = a[i,:] / (5.0 * i) \n result = a\n ### END SOLUTION\n return result"}
{"task_id": "DSP/464", "completion": "import numpy as np\n\ndef generate_array():\n ### BEGIN SOLUTION\n result = np.random.rand(10, 3)\n ### END SOLUTION\n return result\n\ndef random_selection(from_array):\n ### BEGIN SOLUTION\n dist = abs(from_array - 0.5)\n res = np.zeros(10).astype(float)\n for i in np.arange(res.shape[0]):\n index = dist[i].argmin()\n res[i] = from_array[i][index]\n ### END SOLUTION\n return res"}
{"task_id": "DSP/464", "completion": "import numpy as np\n\ndef generate_array():\n ### BEGIN SOLUTION\n result = np.random.rand(10, 3)\n ### END SOLUTION\n return result\n\ndef random_selection(from_array):\n ### BEGIN SOLUTION\n dist = abs(from_array - 0.5)\n res = np.zeros(10).astype(float)\n for i in np.arange(res.shape[0]):\n index = dist[i].argmin()\n res[i] = from_array[i][index]\n ### END SOLUTION\n return res"}
{"task_id": "DSP/465", "completion": "mpg_data = pd.read_fwf(\"http://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data\",header = None)\nmpg_data.columns = [\"mpg\",\"cylinders\",\"displacement\",\"horsepower\",\"weight\",\"acceleration\",\"model_year\",\"origin\",\"car_name\"]"}
{"task_id": "DSP/465", "completion": "mpg_data = pd.read_fwf(\"http://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data\",header = None)\nmpg_data.columns = [\"mpg\",\"cylinders\",\"displacement\",\"horsepower\",\"weight\",\"acceleration\",\"model_year\",\"origin\",\"car_name\"]"}
{"task_id": "DSP/466", "completion": "mpg_data.horsepower = pd.to_numeric(mpg_data.horsepower, errors='coerce')\nmpg_data"}
{"task_id": "DSP/466", "completion": "mpg_data.horsepower = pd.to_numeric(mpg_data.horsepower, errors='coerce')\nmpg_data"}
{"task_id": "DSP/467", "completion": "mpg_data = mpg_data.dropna()"}
{"task_id": "DSP/467", "completion": "mpg_data = mpg_data.dropna()"}
{"task_id": "DSP/468", "completion": "def get_model_names_smallest_cylinders(dataframe):\n \"\"\"\n Returns the names of the cars with the smallest number of cylinders\n \"\"\"\n car_names = dataframe.loc[dataframe.cylinders == dataframe.cylinders.min()].car_name\n return car_names"}
{"task_id": "DSP/468", "completion": "def get_model_names_smallest_cylinders(dataframe):\n \"\"\"\n Returns the names of the cars with the smallest number of cylinders\n \"\"\"\n car_names = dataframe.loc[dataframe.cylinders == dataframe.cylinders.min()].car_name\n return car_names"}
{"task_id": "DSP/469", "completion": "def calculate_correlation(dataframe, first_column, second_column):\n \"\"\"\n Calculates and returns the correlation coefficient between the two columns in the dataframe.\n \"\"\"\n correlation = dataframe[first_column].corr(dataframe[second_column])\n \n return correlation"}
{"task_id": "DSP/469", "completion": "def calculate_correlation(dataframe, first_column, second_column):\n \"\"\"\n Calculates and returns the correlation coefficient between the two columns in the dataframe.\n \"\"\"\n correlation = dataframe[first_column].corr(dataframe[second_column])\n \n return correlation"}
{"task_id": "DSP/470", "completion": "failed_student_times = np.random.uniform(1,3,12)\npassed_student_times = np.random.uniform(7,10,8)\nall_times = np.concatenate([failed_student_times,passed_student_times])\nexam_result = np.array([0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1])"}
{"task_id": "DSP/470", "completion": "failed_student_times = np.random.uniform(1,3,12)\npassed_student_times = np.random.uniform(7,10,8)\nall_times = np.concatenate([failed_student_times,passed_student_times])\nexam_result = np.array([0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1])"}
{"task_id": "DSP/471", "completion": "all_times = np.random.uniform(1,10,20)\nexam_result = np.array([])\nfor time in all_times:\n if time <= 3:\n exam_result = np.append(exam_result,0)\n elif time >= 7:\n exam_result = np.append(exam_result,1)\n else:\n num = np.random.random()\n if num >= 0.5:\n exam_result = np.append(exam_result,1)\n else:\n exam_result = np.append(exam_result,0)"}
{"task_id": "DSP/471", "completion": "all_times = np.random.uniform(1,10,20)\nexam_result = np.array([])\nfor time in all_times:\n if time <= 3:\n exam_result = np.append(exam_result,0)\n elif time >= 7:\n exam_result = np.append(exam_result,1)\n else:\n num = np.random.random()\n if num >= 0.5:\n exam_result = np.append(exam_result,1)\n else:\n exam_result = np.append(exam_result,0)"}
{"task_id": "DSP/472", "completion": "def error_0(x):\n return -np.log(1-x)\n\ndef error_1(x):\n return -np.log(x)"}
{"task_id": "DSP/472", "completion": "def error_0(x):\n return -np.log(1-x)\n\ndef error_1(x):\n return -np.log(x)"}
{"task_id": "DSP/473", "completion": "page1 = skimage.io.imread(\"images/page1.jpg\")\npage2 = skimage.io.imread(\"images/page2.jpg\")\nplt.imshow(page1)\nplt.title(\"Page 1\")\nplt.show()\n\nplt.imshow(page2)\nplt.title(\"Page 2\")\nplt.show()"}
{"task_id": "DSP/473", "completion": "page1 = skimage.io.imread(\"images/page1.jpg\")\npage2 = skimage.io.imread(\"images/page2.jpg\")\nplt.imshow(page1)\nplt.title(\"Page 1\")\nplt.show()\n\nplt.imshow(page2)\nplt.title(\"Page 2\")\nplt.show()"}
{"task_id": "DSP/474", "completion": "def resize_images(images):\n \"\"\"\n Resizes all images to have the same width\n \"\"\"\n max_width = max([image.shape[1] for image in images])\n padded_images = [np.pad(image, ((0, 0), (0, max_width - image.shape[1])), mode = \"constant\", constant_values = 255) for image in images]\n return padded_images\n\ndef concatenate_images(images):\n \"\"\"\n Concatenates all images vertically (one below the other)\n \"\"\"\n image = np.vstack(resize_images(images))\n return image"}
{"task_id": "DSP/474", "completion": "def resize_images(images):\n \"\"\"\n Resizes all images to have the same width\n \"\"\"\n max_width = max([image.shape[1] for image in images])\n padded_images = [np.pad(image, ((0, 0), (0, max_width - image.shape[1])), mode = \"constant\", constant_values = 255) for image in images]\n return padded_images\n\ndef concatenate_images(images):\n \"\"\"\n Concatenates all images vertically (one below the other)\n \"\"\"\n image = np.vstack(resize_images(images))\n return image"}
{"task_id": "DSP/475", "completion": "with open(\"output/menu.txt\",\"r\") as file:\n menu_content = file.read()\nprint(menu_content)"}
{"task_id": "DSP/475", "completion": "with open(\"output/menu.txt\",\"r\") as file:\n menu_content = file.read()\nprint(menu_content)"}
{"task_id": "DSP/476", "completion": "meals_string = menu_content[:menu_content.index(\"Wine by the Glass\")]\ndef generate_meals_table(meals_string):\n meals_string = os.linesep.join([s for s in meals_string.splitlines() if s])\n text_file = open(\"output/dishes.txt\",\"r+\")\n text_file.write(meals_string)\n text_file.close()\n text_file = open(\"output/dishes.txt\",\"r\")\n meals_table = pd.read_csv(text_file,sep = \";\",header = None)\n text_file.close()\n meals_table.columns = [\"category\",\"dish\",\"price\"]\n return meals_table\ntable = generate_meals_table(meals_string)\ntable"}
{"task_id": "DSP/476", "completion": "meals_string = menu_content[:menu_content.index(\"Wine by the Glass\")]\ndef generate_meals_table(meals_string):\n meals_string = os.linesep.join([s for s in meals_string.splitlines() if s])\n text_file = open(\"output/dishes.txt\",\"r+\")\n text_file.write(meals_string)\n text_file.close()\n text_file = open(\"output/dishes.txt\",\"r\")\n meals_table = pd.read_csv(text_file,sep = \";\",header = None)\n text_file.close()\n meals_table.columns = [\"category\",\"dish\",\"price\"]\n return meals_table\ntable = generate_meals_table(meals_string)\ntable"}
{"task_id": "DSP/477", "completion": "num_items_total = None\nnum_categories_total = None\nnum_items_by_category = None\nmean_price_by_category = None\n\nnum_items_total =meals_table.category.count()\nnum_categories_total = len(meals_table[\"category\"].unique())\nnum_items_by_category = meals_table['category'].value_counts()\nmean_price_by_category = meals_table.groupby('category')['price'].mean()"}
{"task_id": "DSP/477", "completion": "num_items_total = None\nnum_categories_total = None\nnum_items_by_category = None\nmean_price_by_category = None\n\nnum_items_total =meals_table.category.count()\nnum_categories_total = len(meals_table[\"category\"].unique())\nnum_items_by_category = meals_table['category'].value_counts()\nmean_price_by_category = meals_table.groupby('category')['price'].mean()"}
{"task_id": "DSP/478", "completion": "def find_slice(matx):\n ### BEGIN SOLUTION\n return matx[:2, 1:3]\n ### END SOLUTION"}
{"task_id": "DSP/478", "completion": "def find_slice(matx):\n ### BEGIN SOLUTION\n return matx[:2, 1:3]\n ### END SOLUTION"}
{"task_id": "DSP/479", "completion": "def update_slice(matx):\n ### BEGIN SOLUTION\n matx[:2, 1:3] += 1000\n return matx\n ### END SOLUTION"}
{"task_id": "DSP/479", "completion": "def update_slice(matx):\n ### BEGIN SOLUTION\n matx[:2, 1:3] += 1000\n return matx\n ### END SOLUTION"}
{"task_id": "DSP/480", "completion": "def boolean_filter(matx):\n ### BEGIN SOLUTION\n return matx[matx<1.5]\n ### END SOLUTION"}
{"task_id": "DSP/480", "completion": "def boolean_filter(matx):\n ### BEGIN SOLUTION\n return matx[matx<1.5]\n ### END SOLUTION"}
{"task_id": "DSP/481", "completion": "def int_converter(matx):\n ### BEGIN SOLUTION\n return np.array(matx, dtype=np.int)\n ### END SOLUTION"}
{"task_id": "DSP/481", "completion": "def int_converter(matx):\n ### BEGIN SOLUTION\n return np.array(matx, dtype=np.int)\n ### END SOLUTION"}
{"task_id": "DSP/482", "completion": "def selective_replace(matx):\n ### BEGIN SOLUTION\n matx[matx % 2 == 0] = 55\n ### END SOLUTION"}
{"task_id": "DSP/482", "completion": "def selective_replace(matx):\n ### BEGIN SOLUTION\n matx[matx % 2 == 0] = 55\n ### END SOLUTION"}
{"task_id": "DSP/483", "completion": "def row_means(matx):\n ### BEGIN SOLUTION\n return matx.mean(axis = 1)\n ### END SOLUTION"}
{"task_id": "DSP/483", "completion": "def row_means(matx):\n ### BEGIN SOLUTION\n return matx.mean(axis = 1)\n ### END SOLUTION"}
{"task_id": "DSP/484", "completion": "def unique_finder(matx):\n ### BEGIN SOLUTION\n return np.unique(matx)\n ### END SOLUTION"}
{"task_id": "DSP/484", "completion": "def unique_finder(matx):\n ### BEGIN SOLUTION\n return np.unique(matx)\n ### END SOLUTION"}
{"task_id": "DSP/485", "completion": "def first_row_adder(matx):\n ### BEGIN SOLUTION\n return matx + matx[0,:]\n ### END SOLUTION"}
{"task_id": "DSP/485", "completion": "def first_row_adder(matx):\n ### BEGIN SOLUTION\n return matx + matx[0,:]\n ### END SOLUTION"}
{"task_id": "DSP/486", "completion": "var_a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']\nvar_b = (1,2,3,4,5,6,7,8,9,10)"}
{"task_id": "DSP/486", "completion": "var_a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']\nvar_b = (1,2,3,4,5,6,7,8,9,10)"}
{"task_id": "DSP/487", "completion": "dictionary = {}\nfor key, value in zip(var_a, var_b):\n dictionary[key] = value\n \ndictionary.items()"}
{"task_id": "DSP/487", "completion": "dictionary = {}\nfor key, value in zip(var_a, var_b):\n dictionary[key] = value\n \ndictionary.items()"}
{"task_id": "DSP/488", "completion": "lst = [1, 2, 3, 4, 5, 6]\ninds = []\n\n# Loop through the provided list 'lst'. For each element, check if it is an even number.\n# If the element is an even number, add the INDEX of that element to the list 'inds'.\n# Note that you are adding the index to 'inds', not the element itself.\n# Hint: to check if a number is even, you can use the modulo '%' operator.\n# Hint: to loop through an iterable, keeping track of the index, you can use the 'enumerate' function.\n\nfor index, num in enumerate(lst):\n if num % 2 == 0:\n inds.append(index)"}
{"task_id": "DSP/488", "completion": "lst = [1, 2, 3, 4, 5, 6]\ninds = []\n\n# Loop through the provided list 'lst'. For each element, check if it is an even number.\n# If the element is an even number, add the INDEX of that element to the list 'inds'.\n# Note that you are adding the index to 'inds', not the element itself.\n# Hint: to check if a number is even, you can use the modulo '%' operator.\n# Hint: to loop through an iterable, keeping track of the index, you can use the 'enumerate' function.\n\nfor index, num in enumerate(lst):\n if num % 2 == 0:\n inds.append(index)"}
{"task_id": "DSP/489", "completion": "def add2(num1, num2):\n return num1 + num2"}
{"task_id": "DSP/489", "completion": "def add2(num1, num2):\n return num1 + num2"}
{"task_id": "DSP/490", "completion": "other_dictionary = dict()\n\n# We will now fill 'other_dictionary', from data.\n# Loop through the key-value pairs in 'dictionary'.\n# For each key-value pair, if the value is odd, use the 'add2' to add 1 to the value.\n# Add the key and incremented value to 'other_dictionary'.\n# Otherwise, add the key-value pair to 'other_dictionary' as is.\n# Note: to loop through key-value pairs in a dictionary, check out the '.items' method.\n\nkey = 'a'\nfor index in range(len(dictionary)):\n if dictionary[key] % 2 != 0:\n dictionary[key] = add2(dictionary[key], 1)\n key = chr(ord(key) + 1)\n index = index + 1\n \nother_dictionary = dictionary.items()"}
{"task_id": "DSP/490", "completion": "other_dictionary = dict()\n\n# We will now fill 'other_dictionary', from data.\n# Loop through the key-value pairs in 'dictionary'.\n# For each key-value pair, if the value is odd, use the 'add2' to add 1 to the value.\n# Add the key and incremented value to 'other_dictionary'.\n# Otherwise, add the key-value pair to 'other_dictionary' as is.\n# Note: to loop through key-value pairs in a dictionary, check out the '.items' method.\n\nkey = 'a'\nfor index in range(len(dictionary)):\n if dictionary[key] % 2 != 0:\n dictionary[key] = add2(dictionary[key], 1)\n key = chr(ord(key) + 1)\n index = index + 1\n \nother_dictionary = dictionary.items()"}
{"task_id": "DSP/491", "completion": "import numpy as np\nimport scipy as sp\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport sklearn as skl"}
{"task_id": "DSP/491", "completion": "import numpy as np\nimport scipy as sp\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport sklearn as skl"}
{"task_id": "DSP/492", "completion": "a = 1\n### END SOLUTION"}
{"task_id": "DSP/492", "completion": "a = 1\n### END SOLUTION"}
{"task_id": "DSP/493", "completion": "b = '2'\n### END SOLUTION"}
{"task_id": "DSP/493", "completion": "b = '2'\n### END SOLUTION"}
{"task_id": "DSP/494", "completion": "ds = True\n### END SOLUTION"}
{"task_id": "DSP/494", "completion": "ds = True\n### END SOLUTION"}
{"task_id": "DSP/495", "completion": "array = np.array(range(5))\n### END SOLUTION"}
{"task_id": "DSP/495", "completion": "array = np.array(range(5))\n### END SOLUTION"}
{"task_id": "DSP/496", "completion": "def add2(num1, num2):\n return num1 + num2"}
{"task_id": "DSP/496", "completion": "def add2(num1, num2):\n return num1 + num2"}
{"task_id": "DSP/497", "completion": "import numpy as np\nimport scipy as sp\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport sklearn as skl"}
{"task_id": "DSP/497", "completion": "import numpy as np\nimport scipy as sp\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport sklearn as skl"}
{"task_id": "DSP/498", "completion": "MR_filepath='data/rt-polarity.tsv'\nMR_df = pd.read_csv(MR_filepath, sep='\\t',header=None)\nMR_df.columns = ['index', 'label', 'review']"}
{"task_id": "DSP/498", "completion": "MR_filepath='data/rt-polarity.tsv'\nMR_df = pd.read_csv(MR_filepath, sep='\\t',header=None)\nMR_df.columns = ['index', 'label', 'review']"}
{"task_id": "DSP/499", "completion": "def convert_label(label):\n if label == 'pos':\n return 1.0 \n elif label == 'neg':\n return 0.0\n else: \n return label"}
{"task_id": "DSP/499", "completion": "def convert_label(label):\n if label == 'pos':\n return 1.0 \n elif label == 'neg':\n return 0.0\n else: \n return label"}