Relative Content

Tag Archive for pythonnumpy

Correct way to find dimension after broadcasting in numpy

Suppose I am given a few numpy arrays, say a, b and c, which are assumed to be broadcastable. Is there a standard or othwerwise an elegant way to find the array shape after broadcasting? Of course, something like (a+b+c).shape would work, but is very inefficient if I am only interested in the shape of the result.

Way to perform a numpy “argany” or “argfirst”?

I’d like to reduce a multidimensional array along one axis by finding the first value in the other dims that is truthy/matches some condition, or a default value if no matching elements can be found. So far I’m trying to do this for a 3D array with some simple looping as follows: