矩阵运算
In:
#相同大小矩阵的加减乘除
data5 = np.array([[1,2],[3,4]])
data6 = np.ones((2,2))
jia1 = data5 + data6
cheng1 = data5 * data6
print(jia1,'
',cheng1)[[2. 3.]
[4. 5.]]
[[1. 2.]
[3. 4.]]#不同大小矩阵的加减乘除(仅两个矩阵秩数为1时)
data7 = np.array([[1,2],[3,4],[5,6]])
data8_1 = np.ones((1,2)) #行秩为1
data8_2 = np.ones((3,1)) #列秩为1
print(data7 + data8_1)
print('-'*20)
print(data7 + data8_2)[[2. 3.]
[4. 5.]
[6. 7.]]
--------------------
[[2. 3.]
[4. 5.]
[6. 7.]]#矩阵乘法,dot()方法
data9 = np.array([[1,2,3]]) #1*3的矩阵
data10 = np.array([[1,2],[3,4],[5,6]]) #3*2的矩阵
data11 = data9.dot(data10) #1*2的矩阵
print(data11)[[22 28]]