gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 15:53:51 24 4
gpt4 key购买 nike

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com