numpy使用3
矩阵相关应用
import numpy as np
test1 = np.array([[1,2,3],[4,5,6],[7,8,9]])
print(np.linalg.inv(test1))#求逆 求伪逆是pinv
print(np.mean(test1,axis=0))#按行求均值 axis=1按列求均值
print(np.sum(test1,axis=0))#按行求和
结果:
[[-4.50359963e+15 9.00719925e+15 -4.50359963e+15]
[ 9.00719925e+15 -1.80143985e+16 9.00719925e+15]
[-4.50359963e+15 9.00719925e+15 -4.50359963e+15]]
[4. 5. 6.]
[12 15 18]
其他一些相关应用
import numpy as np
test = np.array([[1,2,3],[4,5,6]])
print(test.ravel())#将2*3矩阵拉成一行
结果:
[1 2 3 4 5 6]