Skip to content

Commit Live PR #256

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
10 changes: 9 additions & 1 deletion q01_zeros_array/build.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# %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
import numpy as np
def array_zeros():
zeros_array = np.zeros(((3,4,2)))
return zeros_array






11 changes: 8 additions & 3 deletions q02_zeros_reshaped/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Default imports

import numpy as np
from greyatomlib.python_intermediate.q01_zeros_array.build import array_zeros

# Write your code
zeros_array = np.zeros(((3,4,2)))

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


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

# Enter solution here
# Enter solution here
import numpy as np

def create_3d_array():
N = 3*3*3

numbers = []
for x in range(0,N):
numbers.append(x)

array_number = np.array(numbers)
array_number = array_number.reshape(3,3,3)

return array_number


17 changes: 15 additions & 2 deletions q04_read_csv_data_to_ndarray/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# %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'

# Enter code here
import csv
import numpy as np

def read_csv_data_to_ndarray(path , dtype):

with open(path, 'r') as f:
matches = list(csv.reader(f, delimiter=','))

ipl_matches = np.array(matches[1:] , dtype=dtype)
return ipl_matches


# Enter code here
32 changes: 31 additions & 1 deletion q05_read_csv_data/build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
# %load q05_read_csv_data/build.py
# Default imports
import numpy as np

# Enter code here
# Enter code here
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

def get_unique_matches_count():

no_of_matches_played = 0
with open(path,'r') as csvfile:
csvreader = csv.reader(csvfile)
data = [row for row in csvreader]
np_ipl_data = np.asarray(data)

headers = tuple(np_ipl_data[0])

#slicing main ndarray into required ndarray
match_codes = np_ipl_data[1:,[headers.index('match_code')]]

#reshaping ndarray from 2d to 1d to make a list
match_codes_array = match_codes.reshape(np.product(match_codes.shape))

#converting 1d array to a list and then removing duplicates to get unique values
match_codes_set = set(match_codes_array.tolist())

#length of the set will be the total number of matches played
no_of_matches_played = len(match_codes_set)
return no_of_matches_played

31 changes: 31 additions & 0 deletions q06_get_unique_matches_count/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# %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'

# Enter Code Here

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

def get_unique_matches_count():

no_of_matches_played = 0
with open(path,'r') as csvfile:
csvreader = csv.reader(csvfile)
data = [row for row in csvreader]
np_ipl_data = np.asarray(data)

headers = tuple(np_ipl_data[0])

#slicing main ndarray into required ndarray
match_codes = np_ipl_data[1:,[headers.index('match_code')]]

#reshaping ndarray from 2d to 1d to make a list
match_codes_array = match_codes.reshape(np.product(match_codes.shape))

#converting 1d array to a list and then removing duplicates to get unique values
match_codes_set = set(match_codes_array.tolist())

#length of the set will be the total number of matches played
no_of_matches_played = len(match_codes_set)
return no_of_matches_played

32 changes: 31 additions & 1 deletion q07_get_unique_teams_set/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# %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'

# Enter Code Here

from greyatomlib.python_intermediate.q05_read_csv_data.build import read_ipl_data_csv

path = 'data/ipl_matches_small.csv'
import numpy as np

# Enter Code Here
def get_unique_teams_set():

np_ipl_data = read_ipl_data_csv(path , '|S50')

#team 1 2d array
team_1 = np_ipl_data[1:,[3]]

#reshaping to 1d array
team_1_1d = team_1.reshape(np.product(team_1.shape))

#team 1 2d array
team_2 = np_ipl_data[1:,[4]]

#reshaping to 1d array
team_2_1d = team_2.reshape(np.product(team_2.shape))

#taking union of two lists to remove duplicates and merge two lists in one list
names_of_teames_played = set().union(team_1_1d,team_2_1d)

return names_of_teames_played


17 changes: 16 additions & 1 deletion q08_get_total_extras/build.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
# %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
from greyatomlib.python_intermediate.q05_read_csv_data.build import read_ipl_data_csv
import numpy as np

path = 'data/ipl_matches_small.csv'

def get_total_extras():
np_ipl_data = read_ipl_data_csv(path , '|S50')
#creating tuple for headers

extras = np_ipl_data[:,[17]]
extras_list = extras.reshape(np.product(extras.shape)).tolist()
extras_in = [int(x) for x in extras_list]
return sum(extras_in)