# Tensor (machine learning)

> Canonical: https://skillalmanac.com/glossary/tensor | Last verified: 2026-11-25 | Index status: index-eligible

In machine-learning frameworks, a tensor is a multidimensional array with a uniform data type, commonly numeric but sometimes strings. Scalars, vectors and matrices have zero, one and two axes. Neural models use tensors for data and parameters.

Also called: tensors, tensors machine learning, tensor deep learning, what is a tensor, ML tensor.

## In plain language

In common numerical use, a tensor is a container for numbers arranged on a grid; frameworks such as TensorFlow also support string tensors. One number is the simplest case. A list of numbers is the next. A table of rows and columns is the one after, and a stack of tables is the one after that. A colour photo, for example, can be stored as a grid of pixels with a layer for each colour. Machine-learning software keeps its data and its learned settings in this form, because the same maths can then run on a whole grid at once. The main trap is the shape: a common source of errors is two tensors whose sizes do not line up, or from mixing up which axis means what. Note that this is a simpler idea than the tensors of physics.

## Technical definition

In frameworks such as TensorFlow and PyTorch, a tensor is a multi-dimensional array with a uniform dtype. TensorFlow's guide defines shape as the length of each axis, rank as the number of axes (a scalar is rank 0, a vector rank 1, a matrix rank 2) and size as the total number of items, and says tensors are immutable. PyTorch describes tensors as similar to arrays and matrices, used to encode a model's inputs, outputs and parameters, and able to run on GPUs or other accelerators, with CPU tensors able to share memory with NumPy arrays. The Deep Learning book defines a tensor as an array of numbers arranged on a regular grid with a variable number of axes. Operations such as addition, element-wise multiplication and matrix multiplication act on tensors, and broadcasting can combine different shapes only when the shapes satisfy its compatibility rules.

## How it shows up when you use agents

You rarely handle tensors when you only chat with an agent, but you meet them as soon as an agent writes or debugs model code. A [neural network](/glossary/neural-network) takes tensors in, passes them through layers, and returns tensors out. Libraries such as [PyTorch](/glossary/pytorch) and [TensorFlow](/glossary/tensorflow) are built around them. When Claude Code, Codex or Cursor writes training or inference code, many of the runtime errors you will see are tensor errors.

What breaks when it is misunderstood:

- Shape mismatches. Two tensors must have compatible shapes for an operation, and TensorFlow's guide notes that reshaping will not reorder axes for you.
- Wrong axis meaning. The TensorFlow guide advises keeping track of what each axis means, for example batch, width, height and features.
- Wrong device. PyTorch's tutorial says tensors are created on the CPU by default and must be moved to an accelerator, and that copying large tensors between devices can be costly.

Next action: when an agent's model code fails, ask it to print the shape, dtype and device of each tensor at the failing line before it changes anything. The inspected examples below cover data and memory planning rather than tensor computation or model training. For the hardware side, see [GPU for AI](/glossary/gpu-for-ai).

## Common confusions

- **Tensor versus matrix.** A matrix is a tensor with two axes. A tensor can have more, or fewer.
- **Tensor versus array.** In practice they are close. The TensorFlow guide says tensors are kind of like NumPy arrays, and the PyTorch tutorial says they are very similar to arrays and matrices and can run on GPUs or other accelerators.
- **Rank versus dimension.** TensorFlow's guide defines rank as the number of axes, and warns that a rank-2 tensor does not usually describe a 2D space. Dimension can mean an axis or the size of one.
- **Tensor versus the physics tensor.** The word is shared, but the machine-learning use is the array definition above, as in the Deep Learning book. See [machine learning](/glossary/machine-learning).

## Worked examples in this catalogue

### [data-analysis-eda](https://skillalmanac.com/skills/skill-almanac/data-analysis-eda)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A fixed exploratory-analysis procedure and CSV profiler that keeps findings descriptive, evidenced and caveated.

Why it exercises the concept: This inspected CSV profiler is an adjacent data check, not tensor computation. It shows columns and types that can inform later conversion into framework inputs.

### [huggingface-datasets](https://skillalmanac.com/skills/huggingface/huggingface-datasets)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Reads Hugging Face datasets through the Dataset Viewer API: metadata, rows, search and filters.

Why it exercises the concept: Datasets are the raw material that frameworks turn into tensors. This skill lets you inspect rows and features first, though it does not create tensors.

### [local-model-sizing](https://skillalmanac.com/skills/skill-almanac/local-model-sizing)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A check of whether an open-weight language model will run on a given GPU, Mac or PC, with a script that computes memory needs.

Why it exercises the concept: Model weights are stored as tensors; see [Model weights](/glossary/model-weights). This skill does that sizing for a language model.

## Related terms

- [Neural network](https://skillalmanac.com/glossary/neural-network.md)
- [Deep learning](https://skillalmanac.com/glossary/deep-learning.md)
- [PyTorch](https://skillalmanac.com/glossary/pytorch.md)
- [TensorFlow](https://skillalmanac.com/glossary/tensorflow.md)
- [Machine learning (ML)](https://skillalmanac.com/glossary/machine-learning.md)
- [GPU for AI](https://skillalmanac.com/glossary/gpu-for-ai.md)

## Sources

- [Introduction to Tensors](https://www.tensorflow.org/guide/tensor), TensorFlow (accessed 2026-11-24)
- [Tensors](https://docs.pytorch.org/tutorials/beginner/basics/tensorqs_tutorial.html), PyTorch (accessed 2026-11-24)
- [Deep Learning, chapter 2: Linear Algebra](https://www.deeplearningbook.org/contents/linear_algebra.html), Goodfellow, Bengio and Courville (MIT Press) (accessed 2026-11-24)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-25. [Glossary index](https://skillalmanac.com/glossary.md).
