Tensor

A tensor is a multidimensional array of numbers, a generalization of vectors (1 dimension) and matrices (2 dimensions). It is PyTorch's basic data structure, with a type (dtype), a shape (shape), and a device (CPU or GPU). It can record operations in order to compute gradients.

Example

x = torch.tensor([[1., 2.], [3., 4.]])  # shape (2, 2)

Related concepts

The whole glossary