I have a NumPy
array A
with shape (m,n)
and want to run all the elements through some function f
. For a non-constant function such as for example f(x) = x
or f(x) = x**2
broadcasting works perfectly fine and returns the expected result. For f(x) = 1
, applying the function to my array A
however just returns the scalar 1.
Is there a way to force broadcasting to keep the shape, i.e. in this case to return an array of 1s?