[Numpy-discussion] .max() and zero length arrays
Robert Kern
robert.kern at gmail.com
Mon May 14 14:53:30 EDT 2007
David M. Cooke wrote:
> On Mon, May 14, 2007 at 12:38:58PM -0500, Nick Fotopoulos wrote:
>> Dear all,
>>
>> I find myself frequently wanting to take the max of an array that
>> might have zero length. If it is zero length, it throws an exception,
>> when I would like to gracefully substitute my own value. For example,
>> one solution with lists is to do max(possibly_empty_list +
>> [minimum_value]), but it seems clunky to do a similar trick with
>> arrays and concatenate or to use a try: except: block. What do other
>> people do? If there's no good idiom, would it be possible to add
>> kwargs like default_value and/or minimum_value?
>
> What about if maximum returned negative infinity (for floats)
> or the minimum int? That would make maximum act like sum and product,
> where the identity for those functions is returned:
If possible, I would prefer a way to pass a value to use and raise the error if
no such value is passed rather than hardcode an identity value for min() and max().
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the NumPy-Discussion
mailing list