numpy.broadcast_shapes#

numpy.broadcast_shapes(*args)[源代码]#

将输入形状广播为单个形状.

Learn more about broadcasting here .

在 1.20.0 版本加入.

参数:
args整数元组或整数

要相互广播的形状.

返回:
元组

广播的形状.

Raises:
ValueError

如果形状不兼容,并且无法根据NumPy的广播规则进行广播.

示例

>>> import numpy as np
>>> np.broadcast_shapes((1, 2), (3, 1), (3, 2))
(3, 2)
>>> np.broadcast_shapes((6, 7), (5, 6, 1), (7,), (5, 1, 7))
(5, 6, 7)