PyTorch 2 · Tensors

Reshape a tensor

Change the shape. -1 infers one dimension.

x.reshape(-1, 2)
x.unsqueeze(0)
x.squeeze()

Official PyTorch 2 documentation

More tensors commands

All tensors commands · PyTorch 2 cheatsheet

Was this page helpful?