Shortcuts

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].shape but 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.

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources