diff --git a/q01_zeros_array/build.py b/q01_zeros_array/build.py index 5501f7a..3d5c530 100644 --- a/q01_zeros_array/build.py +++ b/q01_zeros_array/build.py @@ -1,8 +1,23 @@ +# %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 +def array_zero(): + + zeros_array=np.zeros((3,4,2)) + + return zeros_array +array_zero +def array_zeros(): + zeros_array=np.zeros((3,4,2)) + return zeros_array +def xyc(): + ba=np.zeros((3,4,2)) + return ba +xyc + + -# Your solution diff --git a/q02_zeros_reshaped/build.py b/q02_zeros_reshaped/build.py index ed629c7..3999705 100644 --- a/q02_zeros_reshaped/build.py +++ b/q02_zeros_reshaped/build.py @@ -1,5 +1,12 @@ +# %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 +def array_reshaped_zeros(): + zeros_array=np.zeros((3,4,2)) + zeros_array_reshaped=zeros_array.reshape(2,3,4) + return zeros_array_reshaped + + diff --git a/q03_create_3d_array/build.py b/q03_create_3d_array/build.py index 7bb6e2f..c3a55c5 100644 --- a/q03_create_3d_array/build.py +++ b/q03_create_3d_array/build.py @@ -1,4 +1,12 @@ +# %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(): + x=np.arange(27) + y=x.reshape(3,3,3) + return y +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..9cdbb92 100644 --- a/q04_read_csv_data_to_ndarray/build.py +++ b/q04_read_csv_data_to_ndarray/build.py @@ -1,5 +1,31 @@ +# %load q04_read_csv_data_to_ndarray/build.py # Default Imports import numpy as np -path = "./data/ipl_matches_small.csv" +import csv +path = './data/ipl_matches_small.csv' + + + +def read_csv_data_to_ndarray(path,datatype=np.float64): + data = np.genfromtxt(path, dtype=datatype,delimiter=',', skip_header=1) + return data +read_csv_data_to_ndarray('./data/ipl_matches_small.csv') +import numpy as np +import csv +data_path = './data/ipl_matches_small.csv' +with open(data_path, 'r') as f: + reader = csv.reader(f, delimiter=',') + # get header from first row + headers = next(reader) + # get all the rows as a list + data = list(reader) + # transform data into numpy array + data = np.array(data).astype(str) +type(data) +import csv +data_path = './data/ipl_matches_small.csv' +data = np.genfromtxt(data_path, delimiter=',', skip_header=1,dtype=np.float64) +data +type(data) + -# 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..5e52b5a 100644 --- a/q05_read_csv_data/build.py +++ b/q05_read_csv_data/build.py @@ -1,4 +1,16 @@ +# %load q05_read_csv_data/build.py # Default imports import numpy as np +import csv +path = './data/ipl_matches_small.csv' + +def read_ipl_data_csv(path,dtype='float64'): + 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') + -# 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..62bd9cf 100644 --- a/q06_get_unique_matches_count/build.py +++ b/q06_get_unique_matches_count/build.py @@ -1,5 +1,37 @@ +# %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 +import csv # Enter Code Here +def get_unique_matches_count(): + with open(path, 'r') as f: + reader = csv.reader(f, delimiter=',') + headers = next(reader) + data = list(reader) + arr=np.array(data) + ar2=arr[0:,0:1] + ar3=np.unique(ar2) + ipl_matches_array=np.size(ar3) + return ipl_matches_array +get_unique_matches_count() +get_unique_matches_count() +path = 'data/ipl_matches_small.csv' +import csv +with open(path, 'r') as f: + reader = csv.reader(f, delimiter=',') + headers = next(reader) + data = list(reader) + arr=np.array(data) + ar2=arr[0:,0:1] + ar3=np.unique(ar2) + type(ar3) + + + +type(ar3) +np.size(ar3) + + diff --git a/q07_get_unique_teams_set/build.py b/q07_get_unique_teams_set/build.py index 17fefd2..3e69903 100644 --- a/q07_get_unique_teams_set/build.py +++ b/q07_get_unique_teams_set/build.py @@ -1,5 +1,37 @@ +# %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 +import csv # Enter Code Here +def get_unique_teams_set(): + with open(path, 'r') as f: + reader = csv.reader(f, delimiter=',') + headers = next(reader) + data = list(reader) + ar1=np.array(data) + team1=set(ar1[:,3].astype('|S50')) + team2=set(ar1[:,4].astype('|S50')) + unio=team1.union(team2) + return unio + +get_unique_teams_set() +path = 'data/ipl_matches_small.csv' +import numpy as np +import csv +with open(path, 'r') as f: + reader = csv.reader(f, delimiter=',') + headers = next(reader) + data = list(reader) + ar1=np.array(data) + team1=set(np.unique(ar1[0:,3:4])) + team2=set(np.unique(ar1[0:,4:5])) + print(team1) + print(team2) + print (type((team1.union(team2)))) + + + + diff --git a/q08_get_total_extras/build.py b/q08_get_total_extras/build.py index 95890c1..a8e4929 100644 --- a/q08_get_total_extras/build.py +++ b/q08_get_total_extras/build.py @@ -1,7 +1,37 @@ +# %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 csv path = 'data/ipl_matches_small.csv' +def get_total_extras(): + + + a = np.genfromtxt(path,dtype=None,delimiter=',',skip_header=1) #readfile + + + extras = [] #Creating list to store extra runs. + + + for i,v in enumerate(a): #looping through list + extras.append(a[i][17]) #extras column index(17th is the order) + return sum(extras) +get_total_extras() + + + + + + + + + + + + + + + + -# Enter Code Here \ No newline at end of file