Why does numpy.argmax for a list of all False bools yield zero?

numpy, python

Solution

From the source code:

`In case of multiple occurrences of the maximum values, the indices corresponding to the first occurrence are returned.`

In the case where the vector is all False, the max value is zero so the index of the first occurrence of the max value i.e. 0 is returned.

Problem

I'm using `numpy.argmax` to calculate the first index where `True` can be found in a vector of bools. Invoking on a `pandas.Series` gives me the Series index rather than the element index. I found a subtle bug in my code that popped up when the vector was all False; returning index 0 in this case seems dangerous since True could very well be the case where True was in the first element. What's the design choice for this return value? ``` >>> numpy.argmax([False,False,False]) 0 >>> numpy.argmax([True, False, True]) 0 >>> s = pandas.Series( [ False, False, False ] , index=[3,6,9] ) >>> numpy.argmax(s) 3 >>> s1 = pandas.Series( [ True, False, False ] , index=[3,6,9] ) >>> numpy.argmax(s1) 3 ```

Original source

Related problems