Tensor

A tensor is a multi-dimensional array of numbers, the basic data structure used in deep learning frameworks like PyTorch and TensorFlow to hold inputs, weights, and outputs.

Data & AI

Tensors generalize familiar shapes: a single number is a 0D tensor (scalar), a list is 1D (vector), a table is 2D (matrix), and you can keep adding dimensions — a color image is a 3D tensor (height x width x color channels).

Deep learning frameworks store everything as tensors and can run their math on GPUs for speed. They also track operations automatically so backpropagation can compute gradients.

Examples

Python

import torch

t = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
print(t.shape)
print(t.sum())

Output:

torch.Size([2, 2])
tensor(10.)

Learn it in a lesson

See also

Back to the Dictionary