2024-10-02 00:26:29 发布
网友
有没有更好更快的方式来表达以下的点产品在纽比? 我有以下形状:
>>> h.shape (600L, 400L, 3L) >>> c.shape (400L, 3L)
如果没有循环,我想计算以下内容:
我想用simeple整形是可能的,但我不知道atm是怎么回事。在
您可以使用numpy.einsum
numpy.einsum
ans = einsum('ijk,jk->ij', h, c)
作为沃伦解决方案的一个替代方案,我认为这是最好的,这里有一个未记录的inner1d:
inner1d
>>> from numpy.core.umath_tests import inner1d >>> a = inner1d(h, c) >>> np.allclose(a, ans) True
从其docstring:
inner1d(x1, x2[, out])inner on the last dimension and broadcast on the rest: (i),(i)->()
inner1d(x1, x2[, out])
inner on the last dimension and broadcast on the rest: (i),(i)->()
对于这个特殊情况,在我的系统中,inner1d比np.einsum稍快:
np.einsum
您可以使用
numpy.einsum
作为沃伦解决方案的一个替代方案,我认为这是最好的,这里有一个未记录的
inner1d
:从其docstring:
对于这个特殊情况,在我的系统中,
^{pr2}$inner1d
比np.einsum
稍快:相关问题 更多 >
编程相关推荐