Python机器学习之NumPy库初探
程序员文章站
2023-12-27 22:15:45
...
import numpy as np
from numpy import *
#matrix an overview
mylist=[1,2,3,4,5]
a=10
mymatrix=np.mat(mylist)
print(a*mymatrix)
#special matrix
myzero=np.zeros_like([3,5])
print(myzero)
myzero=np.zeros([3,5])
print(myzero)
myones=np.ones([3,3])
print(myones)
myrand=np.random.rand(3,4)
print(myrand)
myeye=np.eye(3)
print(myeye)
#matrix operation
print(myeye+myones)
print(sum(myones))
mymatrix=np.mat([[1,2,3],[4,5,6],[7,8,9]])
print(multiply(mymatrix,myones))
print(mymatrix*myones)
print(power(mymatrix,2))
print(mymatrix.transpose())
#linalg
print("det:", linalg.det(myeye))
print("inv:", linalg.inv(myeye))
print("rank:", linalg.matrix_rank(myeye))