【发布时间】:2020-06-02 09:50:34
【问题描述】:
我有两个数组,如下所示:
在代码中:
t = np.random.rand(6, 6, 2)
我现在想为轴 0 和轴 1 数组的每个条目计算轴 2 数组(形状为 2 的数组)的点积。
我可以用 for 循环来做到这一点:
Q = np.zeros_like(t)
for i in range(6):
for j in range(6):
Q[i,j] = t[i,j].dot(t[i,j])
如何使用 numpy 函数做到这一点?
我无法让它与.dot、.tensordot 或类似方法一起使用...
t.dot(t) 会产生此错误ValueError: shapes (6,6,2) and (6,6,2) not aligned: 2 (dim 2) != 6 (dim 1),这是意料之中的,但我想规避它。
【问题讨论】:
标签: python numpy matrix-multiplication dot-product numpy-einsum