Skip to content

Numpy

baseball = [180, 215, 210, 210, 188, 176, 209, 200]
import numpy as np
np_baseball = np.array(baseball)

print(np_baseball)

[180 215 210 210 188 176 209 200]

print(type(np_baseball))
<class 'numpy.ndarray'>

x = [4 , 9 , 6, 3, 1]
y = np.array(x)

high = y > 5
print(high)

[False True True False False]

print(y[high])

[9,6]

Addition of NumPy arrays

A=np.array([1,2,3])
B=np.array([2,3,4])

A+B=np.array([3,5,7])

Mean

A=np.array([1,2,3])
print(np.mean(A))

2

Median

A=np.array([1,2,3])
print(np.mean(A))

2

Standard Deviation

np.std(A)

Correlation

np.corrcoef(A[:,0],B[:,1])