Tensors

Implement shapes and source indices with nested lists before using a framework.

1 / 6

Reshape versus transpose

[[1,2,3],[4,5,6]]:

  • Reshape (3,2): [[1,2],[3,4],[5,6]].
  • Transpose: [[1,4],[2,5],[3,6]].
  • Shape () is a scalar; inferred -1 is outside this API.
2 / 6

Reduction removes one axis

  • Axis 0: vary row, preserve column → [5,7,9].
  • Axis 1: vary column, preserve row → [6,15].
  • Matmul contracts an inner dimension: (m,n)@(n,p) → (m,p).
3 / 6

Align broadcasting from the right

(2,1,3) and (4,1):

  • Pad the latter to (1,4,1).
  • Result (2,4,3).
  • (2,3) and (2,) fail at the trailing axis.
4 / 6

Map output indices back to inputs

Output (1,2,2) reads A[1][0][2] and B[2][0].

  • Singleton input axes always use index zero.
  • Padded axes do not consume an input-list level.
  • (1,3)+(3,) retains its leading size-one axis.
5 / 6

Independent checks

  • Separate zero rows must not alias.
  • A scalar times a rank-three tensor retains shape.
  • Bias (h,) repeats across examples in (n,d)@(d,h).
  • Translate Linear weight orientation at the ML→DL handoff.
6 / 6
←/→ or click edges to navigate · ? help · N notes · F fullscreen