Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有 3D A 矩阵 3x3x5(第三维是 5)和 2D B 矩阵(3x3)。我想将 A 和 B 相乘以获得 (3x3x5) 矩阵。然后对生成的 3D 矩阵的元素求和以创建 2D 矩阵 (3x3)。我怎样才能做到这一点?
只需使用*运算符来乘以 numpy 数组。
*
import numpy as np a = np.arange(45).reshape(3, 3, 5) b = np.arange(9).reshape(3, 3) c = a * b print(c) # 3x3x5 array d = np.sum(c, axis=-1) print(d)
d应该是您正在寻找的答案。
d