> For the complete documentation index, see [llms.txt](https://apphp.gitbook.io/artificial-intelligence-with-php/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://apphp.gitbook.io/artificial-intelligence-with-php/machine-learning/mathematics-for-ml/linear-algebra/tensors/definition-of-tensors.md).

# Definition of Tensors

### Visual Representation

To illustrate a tensor in comparison to other mathematical quantities, let’s look at the hierarchy of dimensions in terms of their structure and complexity:

1\. Scalar (0D): A single number that represents magnitude only, such as a temperature or a count, with no direction.

A single value, e.g., $$3$$

2\. Vector (1D): A quantity with both magnitude and direction, represented as an ordered list of scalars. Think of a vector as a point in a straight line with n coordinates (e.g., force in physics).

A list of values, e.g., \[1, 2, 3], where each element has a position along one dimension.

$$\begin{bmatrix} 1 & 2 & 3 \end{bmatrix}$$

3\. Matrix (2D): A 2-dimensional array of numbers, organized into rows and columns. Matrices are useful for transformations in linear algebra, such as rotations and scaling in 2D or 3D space.

A 2D grid of values, e.g.,

$$\begin{bmatrix} 1 & 2 \ 3 & 4 \end{bmatrix}$$

4\. Tensor (3D and higher): A multidimensional array that generalizes scalars, vectors, and matrices to higher dimensions. Tensors can have multiple dimensions (also called “orders” or “ranks”), which can represent complex relationships among data points in machine learning, physics, or computer vision.

A collection of matrices stacked in a third dimension, e.g.,

$$\begin{bmatrix} \begin{bmatrix} 1 & 2 \ 3 & 4 \end{bmatrix}, \begin{bmatrix} 5 & 6 \ 7 & 8 \end{bmatrix} \end{bmatrix}$$

This breakdown presents the increasing complexity of each structure:

| Dimensionality | Representation | Representation              |
| -------------- | -------------- | --------------------------- |
| Scalar         | 0D             | Temperature, count          |
| Vector         | 1D             | Force, velocity             |
| Matrix         | 2D             | Image processing, rotations |
| Tensor         | 3D and higher  | Deep learning, physics      |

### Formal Definitions

#### 1. Multilinear Map Definition

A tensor is formally defined as a multilinear map from a product of vector spaces to a field F (typically real numbers ℝ):

$$T: V\_1^\* \times V\_2^\* \times \ldots \times V\_n^\* \times W\_1 \times W\_2 \times \ldots \times W\_m \rightarrow F$$

where:

* $$V\_1^\* \quad V\_2^\*$$ etc. are dual vector spaces
* $$W\_1, \quad W\_2$$ etc. are vector spaces
* The tensor is contravariant in the $$W$$ arguments
* The tensor is covariant in the $$V^\*$$ arguments

#### 2. Component-Based Definition

A tensor of rank $$(m,n)$$ has components that transform according to: $$T{\prime}{i\_1 \ldots i\_m j\_1 \ldots j\_n} = \sum{k\_1 \ldots k\_m \ell\_1 \ldots \ell\_n} \left( \frac{\partial x{\prime}{i\_1}}{\partial x{k\_1}} \right) \ldots \left( \frac{\partial x{\prime}{i\_m}}{\partial x{k\_m}} \right) \left( \frac{\partial x\_{\ell\_1}}{\partial x{\prime}{j\_1}} \right) \ldots \left( \frac{\partial x{\ell\_n}}{\partial x{\prime}{j\_n}} \right) T{k\_1 \ldots k\_m \ell\_1 \ldots \ell\_n}$$
