diff --git a/q01_zeros_array/build.py b/q01_zeros_array/build.py index 5501f7a..4221518 100644 --- a/q01_zeros_array/build.py +++ b/q01_zeros_array/build.py @@ -1,8 +1,20 @@ +# %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(shape=(3,4,2)) + return zeros_array + + + +var = array_zeros() +var + + + diff --git a/q02_zeros_reshaped/build.py b/q02_zeros_reshaped/build.py index ed629c7..d01ae87 100644 --- a/q02_zeros_reshaped/build.py +++ b/q02_zeros_reshaped/build.py @@ -1,5 +1,14 @@ +# %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 + +zeros_array = array_zeros() +def array_reshaped_zeros(): + zeros_array_reshaped = zeros_array.reshape((2,3,4)) + return zeros_array_reshaped +var = array_reshaped_zeros() +var.shape + diff --git a/q03_create_3d_array/build.py b/q03_create_3d_array/build.py index 7bb6e2f..6421e12 100644 --- a/q03_create_3d_array/build.py +++ b/q03_create_3d_array/build.py @@ -1,4 +1,31 @@ +# %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(): + + actual = [ + [[0, 1, 2], + [3, 4, 5], + [6, 7, 8]], + + [[9, 10, 11], + [12, 13, 14], + [15, 16, 17]], + + [[18, 19, 20], + [21, 22, 23], + [24, 25, 26]] + ] + var = np.array(actual) +#N = var.size + N = np.count_nonzero(var) + array2 = np.arange(N-1) + var.reshape((3,3,3)) + return var +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..5fcdc15 100644 --- a/q04_read_csv_data_to_ndarray/build.py +++ b/q04_read_csv_data_to_ndarray/build.py @@ -1,5 +1,17 @@ +# %load q04_read_csv_data_to_ndarray/build.py # Default Imports import numpy as np -path = "./data/ipl_matches_small.csv" +from numpy import genfromtxt + +path = './data/ipl_matches_small.csv' +input_dtype = '|S100' +# Enter code here +def read_csv_data_to_ndarray(path,input_dtype): + my_data = genfromtxt(path, dtype = input_dtype,delimiter=',',skip_header=1) + np.array(my_data) + return my_data +ipl_array = read_csv_data_to_ndarray('data/ipl_matches_small.csv', input_dtype) + +ipl_array + -# 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..6973e49 100644 --- a/q05_read_csv_data/build.py +++ b/q05_read_csv_data/build.py @@ -1,4 +1,18 @@ +# %load q05_read_csv_data/build.py # Default imports import numpy as np +from numpy import genfromtxt + +# Enter code here +path = './data/ipl_matches_small.csv' +input_dtype = '|S50' +def read_ipl_data_csv(path,dtype): + ipl_matches_array = genfromtxt(path, dtype = dtype,delimiter=',',skip_header=1) + np.array(ipl_matches_array) + return ipl_matches_array + +ipl_matches_array = read_ipl_data_csv('data/ipl_matches_small.csv',input_dtype) + +ipl_matches_array + -# 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..8cf1407 100644 --- a/q06_get_unique_matches_count/build.py +++ b/q06_get_unique_matches_count/build.py @@ -1,5 +1,25 @@ +# %load q06_get_unique_matches_count/build.py # Default imports from greyatomlib.python_intermediate.q05_read_csv_data.build import read_ipl_data_csv +#import numpy as np +from numpy import genfromtxt +import pandas as pd path = 'data/ipl_matches_small.csv' # Enter Code Here + +matches = pd.read_csv('data/ipl_matches_small.csv') +#genfromtxt(path,delimiter=',',skip_header=1) +matches.head() +type(matches) +temp = matches['match_code'].nunique() +temp +def get_unique_matches_count(): + # data = genfromtxt(path,delimiter=',',skip_header=1) + # ipl_matches_array = np.unique(data,return_counts = True) + ipl_matches_array = matches['match_code'].nunique() + return ipl_matches_array +get_unique_matches_count() + + + diff --git a/q08_get_total_extras/build.py b/q08_get_total_extras/build.py index 95890c1..b16e62d 100644 --- a/q08_get_total_extras/build.py +++ b/q08_get_total_extras/build.py @@ -1,7 +1,16 @@ +# %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 +import pandas as pd path = 'data/ipl_matches_small.csv' -# Enter Code Here \ No newline at end of file +# Enter Code Here +matches = pd.read_csv(path) +matches['extras'].sum() +def get_total_extras (): + extras = matches['extras'].sum() + return extras +get_total_extras() +