【问题标题】:Truth error while trying to find all equal minimum values in array, then retrieve indices尝试在数组中找到所有相等的最小值时出现真值错误,然后检索索引
【发布时间】:2018-09-23 22:12:47
【问题描述】:

我正在尝试查找数组中的所有最小值并检索它们的索引。

import numpy as np
a = np.array([[1,2],[1,4]])
minE = np.min(a)
ax,ay = np.unravel_index(minE, a.shape)

只返回minE = 1ax, ay = 0 1

谁能帮助我,同时为所有等值最小值提供索引(这里是两个 1 的索引)?

【问题讨论】:

  • 请给我们看一段代码,不仅仅是min()函数。
  • @DanieleCappuccio 抱歉,我已经清理过了!

标签: python-2.7 numpy minimum


【解决方案1】:

你在找这个吗:

x = np.array([[1,2,3],[1,4,2]])
np.where(x == np.amin(x))

【讨论】:

  • 太棒了!!非常感谢:)
猜你喜欢
  • 2017-12-23
  • 2011-05-08
  • 2019-03-01
  • 2021-10-26
  • 2020-01-14
  • 2015-07-30
  • 2017-06-21
  • 2018-05-20
  • 1970-01-01
相关资源
最近更新 更多