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 + + + + 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 + + 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 + + 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 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 + 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 + 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 + + 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) +