No history yet

Introduction to Tensors

Beyond Vectors

You're already familiar with scalars (just a single number) and vectors (a list of numbers representing magnitude and direction). These are powerful tools, but sometimes they aren't enough to describe what's happening in the world.

Imagine stretching a rubber band. If you pull on one point, the material stretches not just in that direction, but in others as well. A single vector can't capture this complex, multi-directional response. We need a more general mathematical object. This is where tensors come in.

tensor

noun

A mathematical object that generalizes scalars, vectors, and matrices to higher dimensions. It's a container for data that can describe relationships between different sets of vectors.

Think of tensors as a way to organize information that has multiple directions or components associated with it. Just as a vector is an ordered list of numbers, a tensor is an ordered grid of numbers. The complexity of this grid is described by its rank (sometimes called order or degree).

All of deep learning is computations on tensors, which are generalizations of a matrix that can be indexed in more than 2 dimensions.

A Family of Ranks

The rank of a tensor tells you how many indices are needed to specify a particular element within it. This might sound abstract, but you've been using low-rank tensors all along.

Rank-0 Tensor: A Scalar A scalar is just a single number, like temperature (25°C25°C) or mass (55 kg). It has magnitude but no direction. It requires zero indices to identify it, because there's only one value.

Rank-1 Tensor: A Vector A vector is a list of numbers, like a velocity of (3,4)(3, 4) m/s. It has both magnitude and direction. To specify an element, you need one index. For a vector vv, we might ask for the first component, v1v_1, or the second, v2v_2.

Rank-2 Tensor: A Matrix A matrix is a grid of numbers, arranged in rows and columns. A great example is stress in a material. To specify an element, you need two indices: one for the row and one for the column. For a matrix MM, we'd specify an element as MijM_{ij}.

Higher-Order Tensors Anything with a rank greater than 2 is a higher-order tensor. A rank-3 tensor is like a cube of numbers, requiring three indices (TijkT_{ijk}) to locate an element. You can think of it as a collection of matrices stacked together, like pages in a book.

Working with Tensors

Basic operations on tensors are straightforward extensions of what you already know from vectors and matrices. Tensors are powerful because these simple rules allow us to manipulate complex, multi-dimensional data in a consistent way.

Addition and Subtraction: You can only add or subtract tensors of the same rank and same dimensions. The operation is done element-wise, just like with matrices.

Cij=Aij+BijC_{ij} = A_{ij} + B_{ij}

Scalar Multiplication: To multiply a tensor by a scalar, you simply multiply every element of the tensor by that scalar. This scales the tensor without changing its rank or dimensions.

Bijk=cAijkB_{ijk} = c \cdot A_{ijk}

One new and crucial operation is tensor contraction. This process reduces the rank of a tensor. It involves summing over a pair of indices, one upper (contravariant) and one lower (covariant). For now, let's think of it as a generalization of the dot product.

For example, contracting a rank-2 tensor TijT_{ij} with a rank-1 tensor (a vector) vjv_j involves summing over the shared index jj. The result is a new vector, uiu_i.

ui=jTijvju_i = \sum_j T_{ij} v_j

This operation is fundamental in physics and engineering. It's how we apply transformations (like rotations, represented by a rank-2 tensor) to objects (like position vectors, rank-1 tensors) to find their new state.

Lesson image

Before we test your knowledge, let's review the key ideas with some flashcards.

Ready to check your understanding?

Quiz Questions 1/5

Which of the following best describes why a tensor might be needed instead of a simple vector?

Quiz Questions 2/5

What does the 'rank' of a tensor fundamentally define?

Understanding tensors as a generalization of scalars and vectors opens up a new way to describe the physical world and manage complex data. From here, you can explore how these objects transform and interact in more advanced scenarios.