Broadcasting refers to how numpy treats arrays having different size while working with operators. The smaller array is generally broadcasted across the larger array.
So this recipe is a short example on what does broadcasting mean with respect to numpy. Let's get started.
import numpy as np
Let's pause and look at these imports. Pandas is generally used for performing mathematical operation and preferably over arrays.
Let us create a two simple simple arrays of size 2x3 and 1x3.
X and y are of different size. Performing any mathematical operation over them is considered as broadcasting. Here, the values of y get added to value of x depending upon its position.
Simply use print function to print z
Once we run the above code snippet, we will see:
[[2 4 6] [5 7 9]]