Tensor by Tensor

02.02 · UNIT 01 · Regression and tensor mechanics · Lesson

Tensors, shapes, and broadcasting

A tensor stores numbers along named-by-you axes. Shape records each axis length.

PLAIN-LANGUAGE INTRODUCTION

What is this?

A tensor stores numbers along named-by-you axes. Shape records each axis length.

One simple example

Add [10,20] to [[1,2],[3,4],[5,6]]. Broadcasting returns [[11,22],[13,24],[15,26]].

What goes in?

A tensor with shape (3,2) and a vector with shape (2,).

What comes out?

A tensor with shape (3,2).

Why does it matter?

Shape checks prevent silent mistakes in model calculations.

What is it not?

Broadcasting does not know whether an axis means examples or features.

WORK THROUGH THE IDEA

See the idea in more detail

  1. A tensor is a numbered grid. Shape (3,2) means three rows and two columns.
  2. Here, rows represent examples. Columns represent two features. Your program gives axes these meanings.
  3. The vector [10,20] has one value per column. Broadcasting repeats it across all three rows.
  4. The first row becomes [1+10, 2+20] = [11,22]. The other rows follow the same rule.
  5. Common mistake: a compatible shape can still represent the wrong axis meaning.
Open the detailed notes ↗