PyTorch 2 · Tensors

Create tensors

Create tensors from data, zeros, ones or random values.

x = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
zeros = torch.zeros(3, 4)
rand = torch.rand(2, 3)

Official PyTorch 2 documentation

More tensors commands

All tensors commands · PyTorch 2 cheatsheet

Was this page helpful?