Broadcasting¶

In [2]:
%pip install numpy
import numpy as np
Requirement already satisfied: numpy in /home/samrat/Documents/numpy-torch-tutorials/venv/lib/python3.8/site-packages (1.24.4)
Note: you may need to restart the kernel to use updated packages.

Broadcasting Rules: Suppose we want to add two arrays, A an B.

  • Moving backwards from the last dimension of the array, we check if their dimensions are compatible
  • Dimensions are compatible if they are equal or if either is one
  • If all dimensions of A are compatible with B or vice versa then the arrays are compatible