Learn practical skills, build real-world projects, and advance your career
import torch

Tensors

At its core, PyTorch is a library for processing tensors. A tensor is a number, vector, matrix, or any n-dimensional array. Let's create a tensor with a single number.

# Number
t1 = torch.tensor(4.)
t1
tensor(4.)

4. is a shorthand for 4.0. It is used to indicate to Python (and PyTorch) that you want to create a floating-point number. We can verify this by checking the dtype attribute of our tensor.

t1.dtype
torch.float32