Skip to content
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
5 changes: 3 additions & 2 deletions q01_zeros_array/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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
7 changes: 6 additions & 1 deletion q02_zeros_reshaped/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
import numpy as np
from greyatomlib.python_intermediate.q01_zeros_array.build import array_zeros

# Write your code
old_array = array_zeros()

def array_reshaped_zeros():
zeros_array_reshaped = old_array.reshape((2,3,4))

return zeros_array_reshaped
8 changes: 7 additions & 1 deletion q03_create_3d_array/build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Default Imports
import numpy as np

# Enter solution here
def create_3d_array():
initial_array = np.zeros((3,3,3))
N = initial_array.size
new_array= np.arange(0, N)
desired_array = new_array.reshape((3,3,3))

return desired_array
7 changes: 6 additions & 1 deletion q04_read_csv_data_to_ndarray/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Default Imports
import numpy as np
path = "./data/ipl_matches_small.csv"
dtype = "|S50"

# Enter code here
def read_csv_data_to_ndarray(path, dtype):
with open(path, 'r') as stream:
out_array = np.genfromtxt(stream, skip_header=1, delimiter=',', dtype=dtype)

return out_array
9 changes: 7 additions & 2 deletions q05_read_csv_data/build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Default imports
import numpy as np
from q04_read_csv_data_to_ndarray.build import read_csv_data_to_ndarray

# Enter code here
path = "./data/ipl_matches_small.csv"

def read_ipl_data_csv(path, dtype = "|S50"):

ipl_matches_array = read_csv_data_to_ndarray(path, dtype)
return ipl_matches_array
18 changes: 16 additions & 2 deletions q06_get_unique_matches_count/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Default imports
import numpy as np
from greyatomlib.python_intermediate.q05_read_csv_data.build import read_ipl_data_csv
path = 'data/ipl_matches_small.csv'

# Enter Code Here
# Define function get_unique_matches_count and pass the loaded array to read each element
# and fetch the first element (Match Code). Once all the element[0] are extracted and loaded
# in new numpy array get_unique_id, execute a unique numpy function to return unique match codes
# and then get the count using in built size function
get_unique_id=[]
def get_unique_matches_count():
#Call the function read_ipl_data_csv to load the file into numpy array-2D
get_array = read_ipl_data_csv(path, "|S50")

for element in get_array:
get_unique_id.append(element[0])

Count_val = np.unique(get_unique_id, return_index=False, return_counts=True)[0]
Count = np.size(Count_val)
return Count
18 changes: 16 additions & 2 deletions q07_get_unique_teams_set/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Default imports
import numpy as np
from greyatomlib.python_intermediate.q05_read_csv_data.build import read_ipl_data_csv
path = "data/ipl_matches_small.csv"

# Enter Code Here
# In the newly defined function get_unique_teams_set firstly
# Call the read_ipl_data_csv function to load the data into numpy array
# Using for loop create two sets of numpy array for team1 and team2
# Form a Union of above two set to give the final unique set "variable"

set_team1=[]
set_team2=[]

def get_unique_teams_set():
array_fl = read_ipl_data_csv(path,"|S50")
for element in array_fl:
set_team1.append(element[3])
set_team2.append(element[4])
variable = set(set_team1) | set(set_team2)
return variable
13 changes: 12 additions & 1 deletion q08_get_total_extras/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@

path = 'data/ipl_matches_small.csv'

# Enter Code Here
#Using the newly defined function get_total_extras
# Load the data into array using the existing module read_ipl_data_csv
# Using for loop add the extra into sum and return the same (Loop through since we need to calculate for whole match)
# Since element[17] is an Int (Append/Sum) functionality was throwing error
# Also note element[17] will be an Str so need to convert into Integer before performing the summation.

def get_total_extras():
Sum=0
array_f2 = read_ipl_data_csv(path, "|S50")
for element in array_f2:
Sum += int(element[17])
return Sum