Skip to content

Commit Live PR #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion q01_zeros_array/build.py
Original file line number Diff line number Diff line change
@@ -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


7 changes: 7 additions & 0 deletions q02_zeros_reshaped/build.py
Original file line number Diff line number Diff line change
@@ -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


10 changes: 9 additions & 1 deletion q03_create_3d_array/build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# %load q03_create_3d_array/build.py
# Default Imports
import numpy as np

# Enter solution here
# Enter solution here
def create_3d_array():
x=np.arange(27)
y=x.reshape(3,3,3)
return y
create_3d_array()


30 changes: 28 additions & 2 deletions q04_read_csv_data_to_ndarray/build.py
Original file line number Diff line number Diff line change
@@ -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
14 changes: 13 additions & 1 deletion q05_read_csv_data/build.py
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions q06_get_unique_matches_count/build.py
Original file line number Diff line number Diff line change
@@ -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)


34 changes: 33 additions & 1 deletion q07_get_unique_teams_set/build.py
Original file line number Diff line number Diff line change
@@ -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))))




32 changes: 31 additions & 1 deletion q08_get_total_extras/build.py
Original file line number Diff line number Diff line change
@@ -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