broadcast_shapes

paddle. broadcast_shapes ( *shapes: Sequence[int] ) [源代码]

计算多个 Tensor shape 经过广播(broadcasting)之后的结果 shape。

参数

  • shapes (Sequence[int]) - 一个或多个 Tensor 的 shape。每个 shape 都是一个整数序列(List 或 Tuple)。

返回

list[int],广播后的结果 shape。

代码示例

>>> import paddle

>>> shape = paddle.broadcast_shapes([2, 1, 3], [1, 3, 1])
>>> shape
[2, 3, 3]

>>> # shape = paddle.broadcast_shapes([2, 1, 3], [3, 3, 1])
>>> # ValueError (terminated with error message).

>>> shape = paddle.broadcast_shapes([5, 1, 3], [1, 4, 1], [1, 1, 3])
>>> shape
[5, 4, 3]

>>> # shape = paddle.broadcast_shapes([5, 1, 3], [1, 4, 1], [1, 2, 3])
>>> # ValueError (terminated with error message).