It’s generally unacceptable to scientific computation libraries (like Numpy) if you pass input of different dimensions/shapes to perform operations. But Numpy still gives the results for the input tensors of the following shapes:
Seems like Numpy is a bit relaxed if there is a certain pattern in the dimensions of input arguments.
And Numpy does this using Broadcasting
Broadcasting is a way to perform an operation between tensors that have similarities in their shapes
Lets see how Numpy does it with an example below:
Numpy does Broadcasting in 3 Steps:
If the dimensions fail both conditions, broadcasting is not possible. As shown below, each of the 3 dimensions pass at least one of the above two conditions:
Once both input tensors get transformed to the same shape, they can proceed with the operation.