PyTorch 2 · Tensors

Convert to and from NumPy

Share memory with NumPy arrays on the CPU.

t = torch.from_numpy(arr)
arr = t.numpy()

Official PyTorch 2 documentation

More tensors commands

All tensors commands · PyTorch 2 cheatsheet

Was this page helpful?