The value you’re looking for has to be either x.max()
or x.min()
so you could do
max(x.min(), x.max(), key=abs)
which is similar to aestrivex’s solution but perhaps more readable? Note this will return the minimum in the case where x.min()
and x.max()
have the same absolute value e.g. -5
and 5
. If you have a preference just order the inputs to max
accordingly.
EDIT: Just to clarify, the idea is to leverage the numpy
methods to reduce down to just two values and then use the key
feature of the builtin max
to arbitrate, since key
is not supported by the numpy
methods.