diff --git a/q01_zeros_array/build.py b/q01_zeros_array/build.py index 5501f7a..d2d6627 100644 --- a/q01_zeros_array/build.py +++ b/q01_zeros_array/build.py @@ -4,5 +4,8 @@ import numpy as np # Your solution +def array_zeros(): + zeros_array = np.zeros(shape =(3,4,2)) + return zeros_array - +#print array_zeros() diff --git a/q02_zeros_reshaped/build.py b/q02_zeros_reshaped/build.py index ed629c7..15585ee 100644 --- a/q02_zeros_reshaped/build.py +++ b/q02_zeros_reshaped/build.py @@ -3,3 +3,10 @@ from greyatomlib.python_intermediate.q01_zeros_array.build import array_zeros # Write your code +def array_reshaped_zeros(): + az = array_zeros() + ay = np.reshape(az,newshape=(2,3,4)) + #print ay + #print(type(ay)) + return ay +#print array_reshaped_zeros() diff --git a/q03_create_3d_array/build.py b/q03_create_3d_array/build.py index 7bb6e2f..923d113 100644 --- a/q03_create_3d_array/build.py +++ b/q03_create_3d_array/build.py @@ -1,4 +1,9 @@ # Default Imports import numpy as np -# Enter solution here \ No newline at end of file +# Enter solution here +def create_3d_array(): + N = 27 + arr = np.arange(0,N).reshape(3,3,3) + return arr +#print create_3d_array() diff --git a/q04_read_csv_data_to_ndarray/build.py b/q04_read_csv_data_to_ndarray/build.py index fb71e6e..d395915 100644 --- a/q04_read_csv_data_to_ndarray/build.py +++ b/q04_read_csv_data_to_ndarray/build.py @@ -2,4 +2,8 @@ import numpy as np path = "./data/ipl_matches_small.csv" -# Enter code here \ No newline at end of file +# Enter code here +def read_csv_data_to_ndarray(path,dtype=np.float64): + narr = np.genfromtxt(path, delimiter=",", dtype = dtype, skip_header=1) + return narr +#print read_csv_data_to_ndarray(path) diff --git a/q05_read_csv_data/build.py b/q05_read_csv_data/build.py index 5c70e6e..5b7ee1d 100644 --- a/q05_read_csv_data/build.py +++ b/q05_read_csv_data/build.py @@ -1,4 +1,9 @@ # Default imports import numpy as np -# Enter code here \ No newline at end of file +# Enter code here +path = "./data/ipl_matches_small.csv" +def read_ipl_data_csv(path,dtype='|S50'): + ipl_matches_array = np.genfromtxt(path, dtype =dtype, delimiter=",", skip_header=1) + return ipl_matches_array +#print read_ipl_data_csv(path) diff --git a/q06_get_unique_matches_count/build.py b/q06_get_unique_matches_count/build.py index 014497e..70b7ccb 100644 --- a/q06_get_unique_matches_count/build.py +++ b/q06_get_unique_matches_count/build.py @@ -1,5 +1,10 @@ # 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' - +ipl_matches_array = {} # Enter Code Here +def get_unique_matches_count(): + ipl_matches_array = len(read_ipl_data_csv(path,dtype='|S50')[0,0]) + return ipl_matches_array +print get_unique_matches_count() diff --git a/q07_get_unique_teams_set/build.py b/q07_get_unique_teams_set/build.py index 17fefd2..4188807 100644 --- a/q07_get_unique_teams_set/build.py +++ b/q07_get_unique_teams_set/build.py @@ -1,5 +1,13 @@ # Default imports 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(): + ipl_matches_array = np.genfromtxt(path,delimiter=',',dtype='|S50',skip_header=1) + team1 = np.unique(ipl_matches_array[:,3]) + team2 = np.unique(ipl_matches_array[:,4]) + result = set(np.union1d(team1,team2)) + + return result +#print get_unique_teams_set() diff --git a/q08_get_total_extras/build.py b/q08_get_total_extras/build.py index 95890c1..2d178dd 100644 --- a/q08_get_total_extras/build.py +++ b/q08_get_total_extras/build.py @@ -1,7 +1,12 @@ # 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(): + ipl_matches_array = np.genfromtxt(path,delimiter=',',dtype='|S50',skip_header=1) + extra_runs_array = ipl_matches_array[0:,17].astype(np.int16) + sum_of_runs = extra_runs_array.sum() + return sum_of_runs +print get_total_extras()