我从以下方面学到了信息:How can I represent an infinite number in Python?
我想找到包含'inf'的数组的最小值
In [330]: residuals
Out[330]:
array([[ 2272.35651718, 1387.71126686, 1115.48728484],
[ 695.08009848, inf, inf],
[ 601.44997093, inf, inf]])
In [331]: min(residuals)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-331-69b09e4201cf> in <module>()
----> 1 min(residuals)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
然而,'inf' 似乎有歧义? 有没有一种聪明的方法可以找到最小值而不是对该数组的每个值运行循环?
请您参考如下方法:
这个问题与 inf 无关,它是使用 python 的内置 min 函数和一个多维的 numpy 数组的副产品。
numpy.min( residuals ) 应该做你想做的,假设你正在寻找任何子数组中的最小元素。
