1.numpy乘法運算中"*"或multiply(),是數組元素逐個計算,具體代碼如下:
import numpy as np # 2-D array: 2 x 3 two_dim_matrix_one = np.array([[1, 2, 3], [4, 5, 6]]) another_two_dim_matrix_one = np.array([[7, 8, 9], [4, 7, 1]]) # 對應元素相乘 element-wise product element_wise = two_dim_matrix_one * another_two_dim_matrix_one print('element wise product: %s' %(element_wise)) # 對應元素相乘 element-wise product element_wise_2 = np.multiply(two_dim_matrix_one, another_two_dim_matrix_one) print('element wise product: %s' % (element_wise_2))
2.numpy乘法運算中dot是按照矩陣乘法的規則來運算的,具體實現代碼如下: