diff --git a/q01_zeros_array/build.py b/q01_zeros_array/build.py index 5501f7a..86f0955 100644 --- a/q01_zeros_array/build.py +++ b/q01_zeros_array/build.py @@ -1,8 +1,12 @@ +# %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)).astype(np.int0) + return zeros_array diff --git a/q02_zeros_reshaped/build.py b/q02_zeros_reshaped/build.py index ed629c7..20612ed 100644 --- a/q02_zeros_reshaped/build.py +++ b/q02_zeros_reshaped/build.py @@ -1,5 +1,11 @@ +# %load q02_zeros_reshaped/build.py # Default imports import numpy as np from greyatomlib.python_intermediate.q01_zeros_array.build import array_zeros +#print array_zeros() # Write your code +def array_reshaped_zeros(): + return array_zeros().reshape((2,3,4)) +array_reshaped_zeros() + diff --git a/q03_create_3d_array/build.py b/q03_create_3d_array/build.py index 7bb6e2f..bc52a08 100644 --- a/q03_create_3d_array/build.py +++ b/q03_create_3d_array/build.py @@ -1,4 +1,11 @@ +# %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(): + N = 3 ** 3 + arr = np.arange(0,N).reshape((3,3,3)) + return arr + + diff --git a/q04_read_csv_data_to_ndarray/build.py b/q04_read_csv_data_to_ndarray/build.py index fb71e6e..9824565 100644 --- a/q04_read_csv_data_to_ndarray/build.py +++ b/q04_read_csv_data_to_ndarray/build.py @@ -1,5 +1,10 @@ +# %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 +def read_csv_data_to_ndarray(path,dtype=np.float64): + return np.genfromtxt(path,dtype=dtype,delimiter=',',skip_header=1) + -# 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..4273ff3 100644 --- a/q05_read_csv_data/build.py +++ b/q05_read_csv_data/build.py @@ -1,4 +1,10 @@ +# %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 +def read_ipl_data_csv(path,dtype=np.float16): + ipl_matches_array = np.genfromtxt(path,skip_header=1,dtype=dtype,delimiter=',') + return ipl_matches_array + + diff --git a/q06_get_unique_matches_count/build.py b/q06_get_unique_matches_count/build.py index 014497e..31a1157 100644 --- a/q06_get_unique_matches_count/build.py +++ b/q06_get_unique_matches_count/build.py @@ -1,5 +1,12 @@ +# %load q06_get_unique_matches_count/build.py # Default imports +import numpy as np from greyatomlib.python_intermediate.q05_read_csv_data.build import read_ipl_data_csv path = 'data/ipl_matches_small.csv' # Enter Code Here +def get_unique_matches_count(): + ipl_matches_array = np.genfromtxt(path,dtype='|S100', skip_header=1, delimiter=',') + return len(set(ipl_matches_array[:,0])) + + diff --git a/q07_get_unique_teams_set/build.py b/q07_get_unique_teams_set/build.py index 17fefd2..71b979a 100644 --- a/q07_get_unique_teams_set/build.py +++ b/q07_get_unique_teams_set/build.py @@ -1,5 +1,13 @@ +# %load q07_get_unique_teams_set/build.py # Default imports +import numpy as np 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 +def get_unique_teams_set(): + data = read_ipl_data_csv(path,'|S100') + team1,team2 = data[:,3],data[:,4] + return set.union(set(team1),set(team2)) + + diff --git a/q08_get_total_extras/build.py b/q08_get_total_extras/build.py index 95890c1..497a0a7 100644 --- a/q08_get_total_extras/build.py +++ b/q08_get_total_extras/build.py @@ -1,7 +1,13 @@ +# %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(): + return sum(np.genfromtxt(path,dtype=np.int16,skip_header = 1, delimiter=',')[:,[17]]) + +get_total_extras() +