np的矩阵乘法
np.dot()方法 —— 矩陣乘法
Usage:np.dot( matrixA, matrixB ) or matrix.dot(matrixB)
example:
import numpy as np# define two matrixs here one = np.array([[1,2,3]]) two = np.array([[4],[5],[6]])# let's take a look at the shape of two matrixs print(one.shape) # (1, 3) print(two.shape) # (3,1)print(np.dot(one,two)) # array([32])print(one.dot(two)) # array([32])np.multiply () 或者 * ,矩陣內(nèi)逐個元素相乘 element-wise
example
import numpy as np# define two matrixs one = np.array([[1,2,3],[4,5,6]]) two = np.array([[1,2,3],[4,5,6]])print(np.multiply(one,two)print( one * two )outputs:
array([[ 1, 4, 9],[16, 25, 36]])另外,對于一維矩陣(相當(dāng)于向量)來說,dot方法計算兩者的內(nèi)積
所謂內(nèi)積,即對兩個向量執(zhí)行點乘運算,就是對這兩個向量對應(yīng)位一一相乘之后求和的操作,所得結(jié)果是一個標(biāo)量。
總結(jié)
- 上一篇: numpy.random.normal
- 下一篇: pytorch的梯度计算以及backwa