Skip to content

Commit Live PR #253

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
9 changes: 8 additions & 1 deletion 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

import numpy as np
def array_zeros():
zeros_array = np.zeros(((3,4,2)))
return zeros_array




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

zeros_array = np.zeros(((3,4,2)))

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



19 changes: 18 additions & 1 deletion q03_create_3d_array/build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
# %load q03_create_3d_array/build.py
# Default Imports

# Enter solution here
import numpy as np

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




18 changes: 15 additions & 3 deletions q04_read_csv_data_to_ndarray/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Default Imports
# %load q04_read_csv_data_to_ndarray/build.py


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

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




29 changes: 28 additions & 1 deletion q05_read_csv_data/build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
# %load q05_read_csv_data/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 pandas as pd

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


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


29 changes: 27 additions & 2 deletions q07_get_unique_teams_set/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# %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"

# Enter Code Here
path = 'data/ipl_matches_small.csv'
import numpy as np

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



15 changes: 14 additions & 1 deletion q08_get_total_extras/build.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
# %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():
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)