Skip to content

Commit Live PR #232

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 8 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
7 changes: 7 additions & 0 deletions q01_zeros_array/build.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# %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





16 changes: 16 additions & 0 deletions q02_zeros_reshaped/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# %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_reshaped = array_zeros().reshape(2,3,4)
return zeros_array_reshaped












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

# Enter solution here
# Enter solution here
def create_3d_array():
#specify desired dimensions
dim1 = 3; dim2 = 3; dim3 = 3
elements = dim1*dim2*dim3
variable = np.arange(elements).reshape(dim1,dim2,dim3)
return variable





18 changes: 16 additions & 2 deletions q04_read_csv_data_to_ndarray/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# %load q04_read_csv_data_to_ndarray/build.py
# Default Imports
import numpy as np
path = "./data/ipl_matches_small.csv"
path = './data/ipl_matches_small.csv'
dtype = None

# Enter code here
def read_csv_data_to_ndarray(path,dtype):
data = np.genfromtxt(path, delimiter = ',',dtype=dtype,skip_header=1)
return data

read_csv_data_to_ndarray(path,dtype)
#type(data)
#print(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
path = './data/ipl_matches_small.csv'
dtype = '|S50'

# Enter code here
def read_ipl_data_csv(path,dtype):
ipl_matches_array = np.genfromtxt(path,delimiter=',',dtype=dtype,skip_header=1)
return ipl_matches_array

read_ipl_data_csv(path,dtype)




# Enter code here
20 changes: 19 additions & 1 deletion q06_get_unique_matches_count/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# %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'
#path = 'data/ipl_matches_small.csv' #path for reference as function should not take any parameter.
import numpy as np

# Enter Code Here
def get_unique_matches_count():

#loading the file in a variable
y=np.genfromtxt('data/ipl_matches_small.csv',dtype=None,delimiter=',')

#Getting unique match code ids by using numpy unique function
#Subtracting 1 from total count as one value among unique cinstitutes for the header
ipl_matches_array = len(np.unique(y[:,0]))-1
return ipl_matches_array


get_unique_matches_count()




28 changes: 27 additions & 1 deletion q07_get_unique_teams_set/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# %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 of the csv file to be passed onto function
path = 'data/ipl_matches_small.csv'

# Enter Code Here
def get_unique_teams_set():

#Loading csv file
a = read_ipl_data_csv(path,dtype=None)

#creating empty set variables so that same team name doesn't get added repeatedly.
team1 = set()
team2 = set()

#Looping thru list and getting inside tuple for team name fetching
for i,v in enumerate(a):
team1.add(a[i][3])
team2.add(a[i][4])

#returning union of two
return team1.union(team2) # team1|team2 would do as well.

#Call to a function -
get_unique_teams_set()




18 changes: 17 additions & 1 deletion q08_get_total_extras/build.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
# %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
# Enter Code Here
def get_total_extras():

#reading file using np.genfromtxt
a = np.genfromtxt(path,dtype=None,delimiter=',',skip_header=1)

#Creating an empty list to store extra runs.
extras = []

#Looping thru each deliveries' extra and storing the value in list
for i,v in enumerate(a):
extras.append(a[i][17]) #17th index is the extra column
return sum(extras)
get_total_extras()