numpy - 理解一维向量上的 np.matmul

标签 numpy matrix multidimensional-array matrix-multiplication numpy-ndarray

a = [1, 2, 3]
b = [10, 10, 10]

np.matmul(a, b) 结果是 60。

numpy 如何乘以 (3,) 和 (3,) 维度并返回点积而不是外积(3 * 3)或抛出错误“维度不匹配”?

最佳答案

这直接来自 numpy.matmul() 的文档:

  • If the first argument is 1-D, it is promoted to a matrix by prepending a 1 to its dimensions. After matrix multiplication the prepended 1 is removed.
  • If the second argument is 1-D, it is promoted to a matrix by appending a 1 to its dimensions. After matrix multiplication the appended 1 is removed.


因此,输入的形状 ab转换为 (1, 3)(3,1)分别在矩阵乘法过程中。

根据矩阵乘法的规则,我们知道:
1 x 3 3 x 1 | |
-------- ===> 总结。

因此,我们将结果作为标量。

关于numpy - 理解一维向量上的 np.matmul,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52712688/

相关文章:

C - 读取和解析方法未获得第二行输入

python - python中的矩阵乘法导致类型错误

python - Numpy 矩阵乘法与矩阵数组

matlab - 如何创建复数对称矩阵?

java - 制作一个二维的 10x2 数组,每个元素设置为字符串 "x"

php - 如何使用 PHP 从按其中某个值分组的多维数组中提取值?

c - 多维数组模式访问

python - 在python中模拟对数螺旋星系

python - operator.ge 行为不一致

c++ - LAPACK dgetrs 与 dgesv