Machine Learning Tutorial – Numpy

Code :

import pandas as details
import numpy as np
data={‘Father’:[10,20,40,50,6], #dictionary
‘Son’:[1,3,6,9,9],
}
obj=details.DataFrame(data)

_x_Mean=obj.loc[:,’Father’].mean()
_y_Mean=obj.loc[:,’Son’].mean()
print(“The Mean of Father : “+str(_x_Mean))
print(“The Mean of Son : “+str(_y_Mean))

Father=[10,20,40,50,6]
data=np.array(Father)
print(data.mean())

Output :

Numpy code

import numpy as np
data=[[2,4,5,3],[4,5,6,3],[4,5,6,3]]
data=np.array(data)
print(data)

print(data.shape)

print("Array: ")
array=np.arange(10)
print(array)
print(data[2:5])
array[5:8]=0
print(array)
print()

print(data+5)
data1=data+5
print("ADD")

print(data1-2)
print()
print(data-2)
print()
print(data*data)

Output :

Numpy output

import numpy as np
X=np.random.randn(3,2) #taking values rondomly
X=np.matrix(X)
print() # print() used for new line
print(“The Matrix x: “)
print(X)
print()

Y=np.random.randn(2,2)
Y=np.matrix(Y)
print(“The Matrix Y: “)
print(Y)
print()
print(“The Matrix XY: “) print(XY)
print()
print(“Arange :”)
data=np.arange(16).reshape((4,4))
print(data)
print(data.T)
print()

print(X.mean())
print()
#printing minimum data
print(X.min())
print()
#printing maximum data
print(X.max())

Output :

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top