【发布时间】:2018-05-18 08:20:21
【问题描述】:
我在python中有一个numpy向量,我想找到向量最大值的索引,条件是它小于1。我有以下示例:
temp_res = [0.9, 0.8, 0.7, 0.99, 1.2, 1.5, 0.1, 0.5, 0.1, 0.01, 0.12, 0.56, 0.89, 0.23, 0.56, 0.78]
temp_res = np.asarray(temp_res)
indices = np.where((temp_res == temp_res.max()) & (temp_res < 1))
但是,我尝试的总是返回一个空矩阵,因为这两个条件无法满足。 HU 想要返回 index = 3 作为最终结果,它对应于 0.99 小于 1 的最大值。我该怎么做?
【问题讨论】:
-
ValueError:具有多个元素的数组的真值不明确。使用 a.any() 或 a.all()
-
@eugenhu 对于数组是的,但仍然令人困惑,不推荐。