diff --git a/q01_zeros_array/build.py b/q01_zeros_array/build.py index 5501f7a..ee624dd 100644 --- a/q01_zeros_array/build.py +++ b/q01_zeros_array/build.py @@ -1,8 +1,15 @@ +# %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 +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..3b53da3 100644 --- a/q02_zeros_reshaped/build.py +++ b/q02_zeros_reshaped/build.py @@ -1,5 +1,21 @@ +# %load q02_zeros_reshaped/build.py # Default imports import numpy as np from greyatomlib.python_intermediate.q01_zeros_array.build import array_zeros # Write your code +def array_reshaped_zeros(): + zeros_array_reshaped = array_zeros().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..aacf8c4 100644 --- a/q03_create_3d_array/build.py +++ b/q03_create_3d_array/build.py @@ -1,4 +1,16 @@ +# %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 +def create_3d_array(): + #specify desired dimensions + dim1 = 3; dim2 = 3; dim3 = 3 + elements = dim1*dim2*dim3 + variable = np.arange(elements).reshape(dim1,dim2,dim3) + return variable + + + + + diff --git a/q04_read_csv_data_to_ndarray/build.py b/q04_read_csv_data_to_ndarray/build.py index fb71e6e..8bd9544 100644 --- a/q04_read_csv_data_to_ndarray/build.py +++ b/q04_read_csv_data_to_ndarray/build.py @@ -1,5 +1,19 @@ +# %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' +dtype = None + +# Enter code here +def read_csv_data_to_ndarray(path,dtype): + data = np.genfromtxt(path, delimiter = ',',dtype=dtype,skip_header=1) + return data + +read_csv_data_to_ndarray(path,dtype) +#type(data) +#print(data) + + + + -# 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..44962ce 100644 --- a/q05_read_csv_data/build.py +++ b/q05_read_csv_data/build.py @@ -1,4 +1,16 @@ +# %load q05_read_csv_data/build.py # Default imports import numpy as np +path = './data/ipl_matches_small.csv' +dtype = '|S50' + +# Enter code here +def read_ipl_data_csv(path,dtype): + ipl_matches_array = np.genfromtxt(path,delimiter=',',dtype=dtype,skip_header=1) + return ipl_matches_array + +read_ipl_data_csv(path,dtype) + + + -# Enter code here \ No newline at end of file diff --git a/q06_get_unique_matches_count/build.py b/q06_get_unique_matches_count/build.py index 014497e..d71151d 100644 --- a/q06_get_unique_matches_count/build.py +++ b/q06_get_unique_matches_count/build.py @@ -1,5 +1,23 @@ +# %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' +#path = 'data/ipl_matches_small.csv' #path for reference as function should not take any parameter. +import numpy as np # Enter Code Here +def get_unique_matches_count(): + + #loading the file in a variable + y=np.genfromtxt('data/ipl_matches_small.csv',dtype=None,delimiter=',') + + #Getting unique match code ids by using numpy unique function + #Subtracting 1 from total count as one value among unique cinstitutes for the header + ipl_matches_array = len(np.unique(y[:,0]))-1 + return ipl_matches_array + + +get_unique_matches_count() + + + + diff --git a/q07_get_unique_teams_set/build.py b/q07_get_unique_teams_set/build.py index 17fefd2..b22db77 100644 --- a/q07_get_unique_teams_set/build.py +++ b/q07_get_unique_teams_set/build.py @@ -1,5 +1,31 @@ +# %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 of the csv file to be passed onto function +path = 'data/ipl_matches_small.csv' # Enter Code Here +def get_unique_teams_set(): + + #Loading csv file + a = read_ipl_data_csv(path,dtype=None) + + #creating empty set variables so that same team name doesn't get added repeatedly. + team1 = set() + team2 = set() + + #Looping thru list and getting inside tuple for team name fetching + for i,v in enumerate(a): + team1.add(a[i][3]) + team2.add(a[i][4]) + + #returning union of two + return team1.union(team2) # team1|team2 would do as well. + +#Call to a function - +get_unique_teams_set() + + + + diff --git a/q08_get_total_extras/build.py b/q08_get_total_extras/build.py index 95890c1..a1048a3 100644 --- a/q08_get_total_extras/build.py +++ b/q08_get_total_extras/build.py @@ -1,7 +1,23 @@ +# %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 +def get_total_extras(): + + #reading file using np.genfromtxt + a = np.genfromtxt(path,dtype=None,delimiter=',',skip_header=1) + + #Creating an empty list to store extra runs. + extras = [] + + #Looping thru each deliveries' extra and storing the value in list + for i,v in enumerate(a): + extras.append(a[i][17]) #17th index is the extra column + return sum(extras) +get_total_extras() + +