In [82]: c = np.einsum('...ij,...j->...i', a, b)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [82], in <cell line: 1>()
----> 1 c = np.einsum('...ij,...j->...i', a, b)
File <__array_function__ internals>:5, in einsum(*args,**kwargs)
File ~\anaconda3\lib\site-packages\numpy\core\einsumfunc.py:1359, in einsum(out, optimize, *operands,**kwargs)
1357 if specified_out:
1358 kwargs['out'] = out
-> 1359 return c_einsum(*operands,**kwargs)
1361 # Check the kwargs to avoid a more cryptic error later, without having to
1362 # repeat default values here
1363 valid_einsum_kwargs = ['dtype', 'order', 'casting']
ValueError: operands could not be broadcast together with remapped shapes
[original->remapped]: (10,10,3,3)->(10,10,3,3) (5,3)->(5,newaxis,3)
2条答案
按热度按时间qv7cva1a1#
所以它试图使用
broadcasting
来匹配尺寸。让我们做
a
(10,10,1,3,3)形状。这样,(10,10,1)部分用b
的(5,)广播:jaql4c8m2#
最终通过以下助手函数绕过了这个问题