From c47352e5b22d801b82d305860206c91d8bcc09dd Mon Sep 17 00:00:00 2001 From: aksmungekar Date: Sat, 8 Sep 2018 17:01:12 +0000 Subject: [PATCH 1/9] Done --- q01_zeros_array/build.py | 10 ++++++++-- q02_zeros_reshaped/build.py | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/q01_zeros_array/build.py b/q01_zeros_array/build.py index 5501f7a..16964c2 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((3,4,2)) + return zeros_array + n=(3,4,2) +zeros_array=np.array(n) +type(zeros_array) +np.zero(4) 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 + + From 81d510ad8ea256feb4b9c7044d6a27b5de01e77c Mon Sep 17 00:00:00 2001 From: aksmungekar Date: Sat, 8 Sep 2018 17:07:21 +0000 Subject: [PATCH 2/9] Done --- q01_zeros_array/build.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/q01_zeros_array/build.py b/q01_zeros_array/build.py index 16964c2..3d5c530 100644 --- a/q01_zeros_array/build.py +++ b/q01_zeros_array/build.py @@ -3,12 +3,21 @@ 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 - n=(3,4,2) -zeros_array=np.array(n) -type(zeros_array) -np.zero(4) +def xyc(): + ba=np.zeros((3,4,2)) + return ba +xyc + + + From ce63f8c826b1f46bd837987df558ce7be32c99a4 Mon Sep 17 00:00:00 2001 From: aksmungekar Date: Sat, 8 Sep 2018 17:20:33 +0000 Subject: [PATCH 3/9] Done --- q03_create_3d_array/build.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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() + + From 84b066200ca334f9b5992d59663196c88576a40b Mon Sep 17 00:00:00 2001 From: aksmungekar Date: Sat, 8 Sep 2018 18:57:36 +0000 Subject: [PATCH 4/9] Done --- q04_read_csv_data_to_ndarray/build.py | 30 +++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) 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 From a1ab11335723017ac268929e32d169073c81d513 Mon Sep 17 00:00:00 2001 From: aksmungekar Date: Sat, 8 Sep 2018 19:29:52 +0000 Subject: [PATCH 5/9] Done --- q05_read_csv_data/build.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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 From 6759c63126762144a6b2fa92cb2060d598dbadcb Mon Sep 17 00:00:00 2001 From: aksmungekar Date: Sat, 8 Sep 2018 19:56:08 +0000 Subject: [PATCH 6/9] Done --- q06_get_unique_matches_count/build.py | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/q06_get_unique_matches_count/build.py b/q06_get_unique_matches_count/build.py index 014497e..e36e479 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() +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) + + From 37597d01d7c49ccf824e4c895e79769a2e1ef344 Mon Sep 17 00:00:00 2001 From: aksmungekar Date: Sat, 8 Sep 2018 19:59:54 +0000 Subject: [PATCH 7/9] Done --- q06_get_unique_matches_count/build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/q06_get_unique_matches_count/build.py b/q06_get_unique_matches_count/build.py index e36e479..62bd9cf 100644 --- a/q06_get_unique_matches_count/build.py +++ b/q06_get_unique_matches_count/build.py @@ -16,7 +16,7 @@ def get_unique_matches_count(): 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 From dcdc3739ba2f7f4392a3e6e22e3c3da42c202951 Mon Sep 17 00:00:00 2001 From: aksmungekar Date: Sun, 9 Sep 2018 10:50:35 +0000 Subject: [PATCH 8/9] Done --- q07_get_unique_teams_set/build.py | 34 ++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) 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)))) + + + + From c950a5f018118505a01fcc67b405e159f6f28bc0 Mon Sep 17 00:00:00 2001 From: aksmungekar Date: Sat, 15 Sep 2018 15:03:27 +0000 Subject: [PATCH 9/9] Done --- q08_get_total_extras/build.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) 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