1、内积运算(dot)
dot既是一个数组方法也是numpy命名空间中的一个函数。
import numpy as np
x = np.array([(1, 2, 3), (4, 5, 6)])
x = np.dot(x, np.ones(3))
print(x)
结果:
[ 6. 15.]
2、numpy.linalg
from numpy.linalg import inv,qr
x = np.random.randn(2, 3)
mat = x.T.dot(x)
inv(mat) # 求方阵的逆
mat.dot(inv(mat))生成的应该是单位阵,只不过在生成逆矩阵inv(mat)时,很多元素 是近似的浮点数,所以得到的也不是刚好的单位阵,而是近似的单位阵。
import numpy as np
A = np.array([[1, 1, 1],[1, 2, 4],[1, 3, 9]])
b = np.array([[2], [3], [5]])
x = np.linalg.solve(A, b) # 求解线性方程组
print("x1={},x2={},x3={}".format(x[0, 0], x[1, 0], x[2, 0]))
import numpy as np
m = np.array([[-1, 1, 0],
[-4, 3, 0],
[1, 0, 2]])
e, f = np.linalg.eig(m) # 特征值分解
print("特征值:", e)
print("特征向量:", f)