From 1dada2abcf7804124dd73125a81ab429e34f7514 Mon Sep 17 00:00:00 2001 From: paragDC Date: Fri, 21 Dec 2018 08:25:32 +0000 Subject: [PATCH 1/8] Done --- q01_zeros_array/build.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/q01_zeros_array/build.py b/q01_zeros_array/build.py index 5501f7a..7eb844d 100644 --- a/q01_zeros_array/build.py +++ b/q01_zeros_array/build.py @@ -1,8 +1,16 @@ +# %load q01_zeros_array/build.py # Default Imports import sys, os sys.path.append(os.path.join(os.path.dirname(os.curdir), '..' )) import numpy as np - # Your solution +import numpy as np +def array_zeros(): + zeros_array = np.zeros(((3,4,2))) + return zeros_array + + + + From c457832463ea9d632942e7b585c519288fba949b Mon Sep 17 00:00:00 2001 From: paragDC Date: Fri, 21 Dec 2018 08:37:00 +0000 Subject: [PATCH 2/8] Done --- q02_zeros_reshaped/build.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/q02_zeros_reshaped/build.py b/q02_zeros_reshaped/build.py index ed629c7..8562c22 100644 --- a/q02_zeros_reshaped/build.py +++ b/q02_zeros_reshaped/build.py @@ -1,5 +1,10 @@ -# Default imports + import numpy as np -from greyatomlib.python_intermediate.q01_zeros_array.build import array_zeros -# Write your code +zeros_array = np.zeros(((3,4,2))) + +def array_reshaped_zeros(): + zeros_array_reshaped = zeros_array.reshape(((2,3,4))) + return zeros_array_reshaped + + From 42c1bbfbc158cdaba2109637f1e94dfa7534cf59 Mon Sep 17 00:00:00 2001 From: paragDC Date: Fri, 21 Dec 2018 08:42:10 +0000 Subject: [PATCH 3/8] Done --- q03_create_3d_array/build.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/q03_create_3d_array/build.py b/q03_create_3d_array/build.py index 7bb6e2f..6189c80 100644 --- a/q03_create_3d_array/build.py +++ b/q03_create_3d_array/build.py @@ -1,4 +1,20 @@ +# %load q03_create_3d_array/build.py # Default Imports import numpy as np -# Enter solution here \ No newline at end of file +# Enter solution here +import numpy as np + +def create_3d_array(): + N = 3*3*3 + + numbers = [] + for x in range(0,N): + numbers.append(x) + + array_number = np.array(numbers) + array_number = array_number.reshape(3,3,3) + + return array_number + + From ddbea4c40f0ee0f84436818e5fc36e5c6140aa9d Mon Sep 17 00:00:00 2001 From: paragDC Date: Fri, 21 Dec 2018 08:47:46 +0000 Subject: [PATCH 4/8] Done --- q04_read_csv_data_to_ndarray/build.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/q04_read_csv_data_to_ndarray/build.py b/q04_read_csv_data_to_ndarray/build.py index fb71e6e..f0a723d 100644 --- a/q04_read_csv_data_to_ndarray/build.py +++ b/q04_read_csv_data_to_ndarray/build.py @@ -1,5 +1,18 @@ +# %load q04_read_csv_data_to_ndarray/build.py # Default Imports import numpy as np -path = "./data/ipl_matches_small.csv" +path = './data/ipl_matches_small.csv' + +# Enter code here +import csv +import numpy as np + +def read_csv_data_to_ndarray(path , dtype): + + with open(path, 'r') as f: + matches = list(csv.reader(f, delimiter=',')) + + ipl_matches = np.array(matches[1:] , dtype=dtype) + return ipl_matches + -# Enter code here \ No newline at end of file From 81ebee3757f407e148d1b09532ab4b7530b45012 Mon Sep 17 00:00:00 2001 From: paragDC Date: Fri, 21 Dec 2018 12:55:15 +0000 Subject: [PATCH 5/8] Done --- q06_get_unique_matches_count/build.py | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/q06_get_unique_matches_count/build.py b/q06_get_unique_matches_count/build.py index 014497e..6321ff0 100644 --- a/q06_get_unique_matches_count/build.py +++ b/q06_get_unique_matches_count/build.py @@ -1,5 +1,36 @@ +# %load q06_get_unique_matches_count/build.py # Default imports from greyatomlib.python_intermediate.q05_read_csv_data.build import read_ipl_data_csv path = 'data/ipl_matches_small.csv' # Enter Code Here + +from greyatomlib.python_intermediate.q05_read_csv_data.build import read_ipl_data_csv +path = 'data/ipl_matches_small.csv' + +import numpy as np +import csv + +def get_unique_matches_count(): + + no_of_matches_played = 0 + with open(path,'r') as csvfile: + csvreader = csv.reader(csvfile) + data = [row for row in csvreader] + np_ipl_data = np.asarray(data) + + headers = tuple(np_ipl_data[0]) + + #slicing main ndarray into required ndarray + match_codes = np_ipl_data[1:,[headers.index('match_code')]] + + #reshaping ndarray from 2d to 1d to make a list + match_codes_array = match_codes.reshape(np.product(match_codes.shape)) + + #converting 1d array to a list and then removing duplicates to get unique values + match_codes_set = set(match_codes_array.tolist()) + + #length of the set will be the total number of matches played + no_of_matches_played = len(match_codes_set) + return no_of_matches_played + From 7ccc48c92f8f9509a020d0a4244ecb3fb7bb8bc6 Mon Sep 17 00:00:00 2001 From: paragDC Date: Fri, 21 Dec 2018 12:58:14 +0000 Subject: [PATCH 6/8] Done --- q05_read_csv_data/build.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/q05_read_csv_data/build.py b/q05_read_csv_data/build.py index 5c70e6e..e330ded 100644 --- a/q05_read_csv_data/build.py +++ b/q05_read_csv_data/build.py @@ -1,4 +1,34 @@ +# %load q05_read_csv_data/build.py # Default imports import numpy as np -# Enter code here \ No newline at end of file +# Enter code here +from greyatomlib.python_intermediate.q05_read_csv_data.build import read_ipl_data_csv +path = 'data/ipl_matches_small.csv' + +import numpy as np +import csv + +def get_unique_matches_count(): + + no_of_matches_played = 0 + with open(path,'r') as csvfile: + csvreader = csv.reader(csvfile) + data = [row for row in csvreader] + np_ipl_data = np.asarray(data) + + headers = tuple(np_ipl_data[0]) + + #slicing main ndarray into required ndarray + match_codes = np_ipl_data[1:,[headers.index('match_code')]] + + #reshaping ndarray from 2d to 1d to make a list + match_codes_array = match_codes.reshape(np.product(match_codes.shape)) + + #converting 1d array to a list and then removing duplicates to get unique values + match_codes_set = set(match_codes_array.tolist()) + + #length of the set will be the total number of matches played + no_of_matches_played = len(match_codes_set) + return no_of_matches_played + From ed2d854c238a7ff721ae7651d0423996af2e37d2 Mon Sep 17 00:00:00 2001 From: paragDC Date: Fri, 21 Dec 2018 13:01:31 +0000 Subject: [PATCH 7/8] Done --- q07_get_unique_teams_set/build.py | 32 ++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/q07_get_unique_teams_set/build.py b/q07_get_unique_teams_set/build.py index 17fefd2..685ba3d 100644 --- a/q07_get_unique_teams_set/build.py +++ b/q07_get_unique_teams_set/build.py @@ -1,5 +1,35 @@ +# %load q07_get_unique_teams_set/build.py # Default imports from greyatomlib.python_intermediate.q05_read_csv_data.build import read_ipl_data_csv -path = "data/ipl_matches_small.csv" +path = 'data/ipl_matches_small.csv' # Enter Code Here + +from greyatomlib.python_intermediate.q05_read_csv_data.build import read_ipl_data_csv + +path = 'data/ipl_matches_small.csv' +import numpy as np + +# Enter Code Here +def get_unique_teams_set(): + + np_ipl_data = read_ipl_data_csv(path , '|S50') + + #team 1 2d array + team_1 = np_ipl_data[1:,[3]] + + #reshaping to 1d array + team_1_1d = team_1.reshape(np.product(team_1.shape)) + + #team 1 2d array + team_2 = np_ipl_data[1:,[4]] + + #reshaping to 1d array + team_2_1d = team_2.reshape(np.product(team_2.shape)) + + #taking union of two lists to remove duplicates and merge two lists in one list + names_of_teames_played = set().union(team_1_1d,team_2_1d) + + return names_of_teames_played + + From 40006f0f82817a9a2ae3532e7cdff4bfde218ea0 Mon Sep 17 00:00:00 2001 From: paragDC Date: Fri, 21 Dec 2018 13:05:29 +0000 Subject: [PATCH 8/8] Done --- q08_get_total_extras/build.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/q08_get_total_extras/build.py b/q08_get_total_extras/build.py index 95890c1..348dd6d 100644 --- a/q08_get_total_extras/build.py +++ b/q08_get_total_extras/build.py @@ -1,7 +1,22 @@ +# %load q08_get_total_extras/build.py # Default Imports from greyatomlib.python_intermediate.q05_read_csv_data.build import read_ipl_data_csv import numpy as np path = 'data/ipl_matches_small.csv' -# Enter Code Here \ No newline at end of file +# Enter Code Here +from greyatomlib.python_intermediate.q05_read_csv_data.build import read_ipl_data_csv +import numpy as np + +path = 'data/ipl_matches_small.csv' + +def get_total_extras(): + np_ipl_data = read_ipl_data_csv(path , '|S50') + #creating tuple for headers + + extras = np_ipl_data[:,[17]] + extras_list = extras.reshape(np.product(extras.shape)).tolist() + extras_in = [int(x) for x in extras_list] + return sum(extras_in) +