diff --git a/q01_zeros_array/build.py b/q01_zeros_array/build.py index 5501f7a..38b3c1c 100644 --- a/q01_zeros_array/build.py +++ b/q01_zeros_array/build.py @@ -1,8 +1,14 @@ +# %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((4,2,3)) + return zeros_array + +array_zeros() diff --git a/q02_zeros_reshaped/build.py b/q02_zeros_reshaped/build.py index ed629c7..54c74e7 100644 --- a/q02_zeros_reshaped/build.py +++ b/q02_zeros_reshaped/build.py @@ -1,5 +1,15 @@ +# %load q02_zeros_reshaped/build.py # Default imports import numpy as np -from greyatomlib.python_intermediate.q01_zeros_array.build import array_zeros +from greyatomlib.python_intermediate.q01_zeros_array.build import array_zeros # Write your code + +def array_reshaped_zeros(): + zeros_array=np.zeros((4,2,3)) + zeros_array_reshaped = zeros_array.reshape(2,3,4) + return zeros_array_reshaped + +array_reshaped_zeros() + + diff --git a/q03_create_3d_array/build.py b/q03_create_3d_array/build.py index 7bb6e2f..527b7c6 100644 --- a/q03_create_3d_array/build.py +++ b/q03_create_3d_array/build.py @@ -1,4 +1,15 @@ +# %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 = 27 + return np.arange(N).reshape(3,3,3) + + + + +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..e85a4b3 100644 --- a/q04_read_csv_data_to_ndarray/build.py +++ b/q04_read_csv_data_to_ndarray/build.py @@ -1,5 +1,15 @@ +# %load q04_read_csv_data_to_ndarray/build.py # Default Imports import numpy as np -path = "./data/ipl_matches_small.csv" -# Enter code here \ No newline at end of file +def read_csv_data_to_ndarray(path,dtype): + #path = './data/ipl_matches_small.csv' + return np.genfromtxt(path,delimiter=',',dtype=dtype,skip_header=1) + +# Enter code here +cally=read_csv_data_to_ndarray('./data/ipl_matches_small.csv','|S20') +cally + + + + diff --git a/q05_read_csv_data/build.py b/q05_read_csv_data/build.py index 5c70e6e..e8270a9 100644 --- a/q05_read_csv_data/build.py +++ b/q05_read_csv_data/build.py @@ -1,4 +1,15 @@ +# %load q05_read_csv_data/build.py # Default imports import numpy as np -# Enter code here \ No newline at end of file +def read_ipl_data_csv(path,dtype): + #path='./data/ipl_matches_small.csv' + ipl_matches_array=np.genfromtxt(path, dtype=dtype, delimiter=',', skip_header=1) + return ipl_matches_array + +# Enter code here + +read_ipl_data_csv('./data/ipl_matches_small.csv','|S50') + + + diff --git a/q06_get_unique_matches_count/build.py b/q06_get_unique_matches_count/build.py index 014497e..d3a7f03 100644 --- a/q06_get_unique_matches_count/build.py +++ b/q06_get_unique_matches_count/build.py @@ -1,5 +1,26 @@ +# %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' +import numpy as np # Enter Code Here +def get_unique_matches_count(): + varfile=np.genfromtxt(path,dtype='|S20',delimiter=',',skip_header=1,) + varcol=varfile[:,0] + ipl_matches_array = np.count_nonzero(np.unique(varcol)) + return ipl_matches_array +varfile=np.genfromtxt(path,dtype='|S20',delimiter=',',skip_header=1,) +get_unique_matches_count() +import numpy as np +path = 'data/ipl_matches_small.csv' +varfile +#for i in varfile: print(i[1],i[2]) +#np.unique(varfile[0]) +#varfile[0] +#ipl_ctr=np.ndarray(shape=(1,0), dtype=float, order='F') +varcol=varfile[:,0] + +np.unique(varcol) + + diff --git a/q07_get_unique_teams_set/build.py b/q07_get_unique_teams_set/build.py index 17fefd2..4a5e9f6 100644 --- a/q07_get_unique_teams_set/build.py +++ b/q07_get_unique_teams_set/build.py @@ -1,5 +1,16 @@ +# %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' +import numpy as np # Enter Code Here +def get_unique_teams_set(): + varfile=np.genfromtxt(path,delimiter=',',skip_header=1,dtype='|S50') + var1=np.unique(varfile[:,3]) + var2=np.unique(varfile[:,4]) + return set(np.union1d(var1,var2)) + +get_unique_teams_set() + + diff --git a/q08_get_total_extras/build.py b/q08_get_total_extras/build.py index 95890c1..c0cd3c3 100644 --- a/q08_get_total_extras/build.py +++ b/q08_get_total_extras/build.py @@ -1,7 +1,14 @@ +# %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(): + varfile=np.genfromtxt(path,delimiter=',',skip_header=1,dtype='int16') + return np.sum(varfile[:,17]) +get_total_extras() + +