我numpy.argmax用来计算True可以在布尔向量中找到的第一个索引。调用a pandas.Series给我系列索引,而不是元素索引。
我在代码中发现了一个细微的错误,当向量全为False时就会弹出;在这种情况下返回索引0似乎很危险,因为True很可能是True在第一个元素中的情况。此返回值的设计选择是什么?
>>> 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
Run Code Online (Sandbox Code Playgroud)
从源代码:
In case of multiple occurrences of the maximum values, the indices
corresponding to the first occurrence are returned.
在向量全为False的情况下,最大值为零,因此返回第一次出现的最大值的索引,即0。
| 归档时间: |
|
| 查看次数: |
1081 次 |
| 最近记录: |