Say I have two objects X
, Y
of shape k,1,n
and k,m,n
. I know that numpy will automatically extend/repeat X
along the first dimension when I do operations such as X + Y
. Does this magic work for all mathematical operations that are supported/included in numpy?
For example, can I do scipy.special.binom(X,Y)
and get the expected result? I have tried some of the special functions, and I don't receive an error. Does not receiving an error allow me to conclude that the broadcasting was done correctly?
numpy
does apply broadcasting for all operators, eg. *+-/ etc. It also applies it where possible toufunc
functions. That's part of theufunc
definition.scipy.special.binom
is, according to its docs aufunc
. It is compiled so I can't look at the code to verify this, but I can do a few simple tests:The (2,3) and (2,4) output dimensions match the broadcasted inputs. That consistent with broadcasting.
np.dot
is an example of anumpy
function where broadcasting does not apply.