注意:必须确保第一个矩阵中的行数等于第二个矩阵中的列数,否则不能进行矩阵乘法运算。
图1:矩阵乘法
import numpy as np array1=np.array([[1,2,3],[4,5,6],[7,8,9]],ndmin=3) array2=np.array([[9,8,7],[6,5,4],[3,2,1]],ndmin=3) result=np.multiply(array1,array2) result输出结果:
array([[[ 9, 16, 21], [24, 25, 24], [21, 16, 9]]])
import numpy as np array1=np.array([[1,2,3],[4,5,6],[7,8,9]],ndmin=3) array2=np.array([[9,8,7],[6,5,4],[3,2,1]],ndmin=3) result=np.matmul(array1,array2) print(result)输出结果:
数组([[[ [30,24,18], [84,69,54 ],[138,114,90]]])
import numpy as np array1=np.array([[1,2,3],[4,5,6],[7,8,9]],ndmin=3) array2=np.array([[9,8,7],[6,5,4],[3,2,1]],ndmin=3) result=np.dot(array1,array2) print(result)输出结果:
array([[[[ 30, 24, 18]], [[ 84, 69, 54]], [[138, 114, 90]]]])
本文链接:http://task.lmcjl.com/news/13692.html