On this page
torch.broadcast_shapes
torch.broadcast_shapes(*shapes) → Size[source]-
Similar to
broadcast_tensors()but for shapes.This is equivalent to
torch.broadcast_tensors(*map(torch.empty, shapes))[0].shapebut avoids the need create to intermediate tensors. This is useful for broadcasting tensors of common batch shape but different rightmost shape, e.g. to broadcast mean vectors with covariance matrices.Example:
>>> torch.broadcast_shapes((2,), (3, 1), (1, 1, 1)) torch.Size([1, 3, 2])- Parameters
-
*shapes (torch.Size) – Shapes of tensors.
- Returns
-
A shape compatible with all input shapes.
- Return type
-
shape (torch.Size)
- Raises
-
RuntimeError – If shapes are incompatible.
© 2024, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://pytorch.org/docs/2.1/generated/torch.broadcast_shapes.html