240 | Big Data Simplied
Sr # Command Purpose Sample Code with Output
5. mean, median Statistical functions
>>> np.mean(a)
18.166666666666668
>>> np.mean(a, axis = 1)
array([14. , 22.33333333])
>>> np.mean(a, axis = 0)
array([20. , 23.5, 11. ])
>>> np.median(a)
16.5
>>> np.median(a, axis = 1)
array([14., 19.])
>>> np.median(a, axis = 0)
array([20. , 23.5, 11. ])
>>> np.std(a)
11.036555420762202
>>> np.var(a)
121.80555555555554
Practice Problem: Write a simple program to take the value of loop counter as input and build a
string array of that size. After that, print array values in a loop. Also, print the entire array at
the end.
import numpy as np
n = int(input(“Enter the array size needed: “))
var2 = np.empty(n, dtype = object)
strval = “”
for i in range (1, n):
var2[i] = “This is string # “ + str(i)
print(var2[i])
print(var2)
Enter the array size needed: 3
This is string # 1
This is string # 2
[None ‘This is string # 1’’This is string # 2’]
M09 Big Data Simplified XXXX 01.indd 240 5/10/2019 10:22:57 AM