mlx.core.broadcast_shapes

mlx.core.broadcast_shapes#

broadcast_shapes(*shapes: Sequence[int]) Tuple[int]#

Broadcast shapes.

Returns the shape that results from broadcasting the supplied array shapes against each other.

Parameters:

*shapes (Sequence[int]) – The shapes to broadcast.

Returns:

The broadcasted shape.

Return type:

tuple

Raises:

ValueError – If the shapes cannot be broadcast.

Example

>>> mx.broadcast_shapes((1,), (3, 1))
(3, 1)
>>> mx.broadcast_shapes((6, 7), (5, 6, 1), (7,))
(5, 6, 7)
>>> mx.broadcast_shapes((5, 1, 4), (1, 3, 1))
(5, 3, 4)