Difference makes the DIFFERENCE
import numpy as np
scores = np.loadtxt("/content/cric_data.tsv", skiprows = 1)
sac = np.loadtxt("/content/cric_data.tsv", skiprows = 1, usecols = 1)
rah = np.loadtxt("/content/cric_data.tsv", skiprows = 1, usecols = 2)
ind = np.loadtxt("/content/cric_data.tsv", skiprows = 1, usecols = 3)
scores
np.min(scores)
np.mean(scores)
np.median(scores)
iqr = np.percentile(scores, 75) - np.percentile(scores, 25)
print(iqr)
iqr = np.percentile(scores, [75, 25])
print(iqr)
print(iqr[0] - iqr[1])
np.mean(sac)
np.mean(rah)
np.mean(ind)
sac_iqr = np.percentile(sac, [75, 25])
sach_iqr = sac_iqr[0] - sac_iqr[1]
print(sach_iqr)
np.median(sac)
print(np.percentile(sac, 50))
print(np.mean(rah))
print(np.median(rah))
rah_iqrs = np.percentile(rah, [75, 25])
print(rah_iqrs[0] - rah_iqrs[1])
np.histogram(sac, 10)
np.histogram(rah, 4)
np.histogram(ind, 20)
np.split?
np.split(sac, 5)
sac25grp = np.split(sac, 25)
sac25grp
np.median(sac25grp[0])
np.median(sac25grp[1])
print(np.mean(sac25grp))
print(np.mean(sac25grp[0:24]))
sac25grp_mean = [np.mean(i) for i in sac25grp]
sac25grp_mean
print([np.mean(i) for i in sac25grp])
print([np.median(i) for i in sac25grp])
rah25grp = np.split(rah, 25)
rah25grp
rah25grp_median = [np.median(i) for i in rah25grp]
rah25grp_median
sac
sacgr100 = [sac[i] for i in sac if sac>100]
sacgr100
sacgr100 = sac > 100
sacgr100
import numpy as np
cric_data = np.loadtxt("/content/cric_data.tsv", skiprows = 1)
cric_data.shape
cric_data = cric_data[:, [1,2,3]]
cric_data
sac = cric_data[:,0]
sac
rah = cric_data[:,1]
rah
india = cric_data[:, 2]
india
def stats(col):
print("Mean is : ", np.mean(col))
print("Median is :", np.median(col))
print("Inter quartile range :", np.percentile(col, 75)
- np.percentile(col, 25))
stats(sac)
stats(rah)
stats(india)
np.mean(cric_data, axis = 0)
np.median(cric_data, axis=0)
np.percentile(cric_data, 75, axis=0) - np.percentile(cric_data, 25, axis = 0)
np.histogram(sac)
sac.shape
sac.reshape(9, 25)
sac_by_25 = sac.reshape(9, 25)
np.mean(sac_by_25, axis = 1)
sac > 100
sac[sac>100]
np.mean(sac[sac > 100])
## Question 5
np.mean(sac[rah <= 10])
np.percentile(india, [25, 50, 75, 100])
qrs = np.percentile(india, [25, 50, 75, 100])
india
india < 175
india[(india < 175)]
india[india < [175, 215]]
qrs
india < qrs
qrs.shape
General Rule(s):
india.shape
qrs = qrs.reshape(4, 1)
qrs.shape
india < qrs
indicies = india < qrs
indicies.shape
qrs
sac
sac[indicies[1, :]]
sac[indicies[0,:]]
for i in range(4): print(i, np.mean(sac[indicies[i]]))
snr = cric_data[0 : 2]
snr
snr = cric_data[:, 0:2]
snr
np.max([1,2,3,4,3,2])
np.argmax([1,2,3,4,3,2])
np.argmax(snr, axis = 1)
is_rahul = np.argmax(snr, axis=1)
is_rahul
np.sum(is_rahul) / 225
where f() - takes three arguments - condition, x, y
np.where(is_rahul, "rahul", "sac")
x_arr = np.arange(0, 101, 5)
x_arr.shape
x_arr
x_arr = x_arr.reshape(x_arr.shape[0], 1)
x_arr
x_arr.shape
sac.shape
sac > x_arr
indicies = sac>x_arr
indicies
indicies.shape
# to get all the scores that are more than 5
sac[indicies[1,:]]
# to get all the scores more than 10
sac[indicies[2, :]]
# to get scores that are more than 15 and likewise...
sac[indicies[3,:]]
np.mean(sac[indicies[1,:]])
np.mean(sac[indicies[2, :]])
np.mean(sac[indicies[3, :]])
# the following code gives us the mean of the scores
for i in range(x_arr.shape[0]):
print(np.mean(sac[indicies[i, :]]))
# we are interested in the incremental scores rather than mean so,
# subtract the ith element (what he has already scored) from the mean
for i in range(x_arr.shape[0]):
print(x_arr[i, 0],
np.mean(sac[indicies[i, :]]) - x_arr[i, 0])
sac_cumsum = np.cumsum(sac)
sac_cumsum
np.histogram(sac_cumsum, bins = np.arange(0, 10000, 1000))
a = np.array([1,2,3,4])
print(a[::-1])
a = np.array([1,2,3,4])
a[0] = 0.9
print(a[0], a.dtype)
a
a = np.arange(3)
b = a.reshape(2,2)
print(b)
a = np.array([1,2,3,4, 5])
print(a[2:None])
a = np.arange(10)
b = np.where(a % 2 == 1, 1, a)
print(b)
a = np.array([[1,2,3], [4,5,6]])
print(a[1][2])
a = np.array([3,6,9,12,15])
b = np.array([2,3,4,5,12])
c = np.where(a == b)
print(c[0])