NumPy broadcasting

A      (4d array):  8 x 1 x 6 x 5
B (3d array): 7 x 1 x 5
Result (4d array): 8 x 7 x 6 x 5

We can grasp the general idea from the above example. Looking from the right to left: if we only have those 3 cases, then the broadcasting is valid:

  1. dimension is the same
  2. one of the dimension is 1
  3. one of the dimensions does not exist.

For the above example, look from right to left

first dimension: A and B are the same, good

second dimension: B is one, good

third dimension: A is one, good

fourth dimension: B doesn't exist, good.

So the broadcasting is valid.

For more details see here.