diff --git a/q01_zeros_array/build.py b/q01_zeros_array/build.py index 5501f7a..b3a97cc 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((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..17c6a0c 100644 --- a/q02_zeros_reshaped/build.py +++ b/q02_zeros_reshaped/build.py @@ -3,3 +3,9 @@ from greyatomlib.python_intermediate.q01_zeros_array.build import array_zeros # Write your code +def array_reshaped_zeros(): + zeros_array = np.zeros((3,4,2)) + zeros_array_reshaped = zeros_array.reshape(2,3,4) + return zeros_array_reshaped + +print (array_reshaped_zeros()) diff --git a/q03_create_3d_array/build.py b/q03_create_3d_array/build.py index 7bb6e2f..95535f5 100644 --- a/q03_create_3d_array/build.py +++ b/q03_create_3d_array/build.py @@ -1,4 +1,10 @@ # Default Imports import numpy as np -# Enter solution here \ No newline at end of file +# Enter solution here +def create_3d_array(): + arr = np.arange(27) + arr1 = arr.reshape(3,3,3) + return arr1 + +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..0c02f5b 100644 --- a/q04_read_csv_data_to_ndarray/build.py +++ b/q04_read_csv_data_to_ndarray/build.py @@ -2,4 +2,10 @@ import numpy as np path = "./data/ipl_matches_small.csv" -# Enter code here \ No newline at end of file +# Enter code here +dtype = np.float64 +def read_csv_data_to_ndarray(path,dtype): + array = np.genfromtxt(path, dtype=dtype, skip_header=1, delimiter=",") + return array + +print (read_csv_data_to_ndarray(path,dtype)) diff --git a/q05_read_csv_data/build.py b/q05_read_csv_data/build.py index 5c70e6e..ecfe9b4 100644 --- a/q05_read_csv_data/build.py +++ b/q05_read_csv_data/build.py @@ -1,4 +1,8 @@ # Default imports import numpy as np -# Enter code here \ No newline at end of file +# Enter code here +dtype='|S20' +def read_ipl_data_csv(path, dtype): + ipl_matches_array = np.genfromtxt(path, dtype=dtype, skip_header=1, 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..4e53210 100644 --- a/q06_get_unique_matches_count/build.py +++ b/q06_get_unique_matches_count/build.py @@ -3,3 +3,14 @@ path = 'data/ipl_matches_small.csv' # Enter Code Here +import numpy as np +dtype = '|S20' +def read_ipl_data_csv(path, dtype): + ipl_matches_array = np.genfromtxt(path, dtype=dtype, skip_header=1, delimiter=",") + return ipl_matches_array + +def get_unique_matches_count(): + ipl_matches_array = read_ipl_data_csv(path, dtype) + return len(set(ipl_matches_array[:,0])) + +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..8ca4b6a 100644 --- a/q07_get_unique_teams_set/build.py +++ b/q07_get_unique_teams_set/build.py @@ -3,3 +3,12 @@ path = "data/ipl_matches_small.csv" # Enter Code Here +import numpy as np +dtype = '|S50' +def get_unique_teams_set(): + var = read_ipl_data_csv(path,dtype) + team1 = set(var[:,3]) + team2 = set(var[:,4]) + return team1.union(team2) + +print (get_unique_teams_set()) diff --git a/q08_get_total_extras/build.py b/q08_get_total_extras/build.py index 95890c1..386e65a 100644 --- a/q08_get_total_extras/build.py +++ b/q08_get_total_extras/build.py @@ -4,4 +4,8 @@ path = 'data/ipl_matches_small.csv' -# Enter Code Here \ No newline at end of file +# Enter Code Here +dtype = np.int +def get_total_extras(): + var = read_ipl_data_csv(path, dtype) + return sum(var[:,17])