【问题标题】:python, indices of minima array [duplicate]python,最小数组的索引[重复]
【发布时间】:2017-03-22 09:38:25
【问题描述】:

我正在 Jupyter Notebook 中使用 python 3。

想象一下我有:

import numpy as np

q = np.array([5, 2, 6, 7, 2])

我现在想找到数组最小值的索引;在这种情况下,数字 1 和 4。

我尝试使用:

np.argmin(q)

这给出了:

1

不幸的是 np.argmin() 仅在只有一个最小值时才有效。如何找到另一个最小值的索引?

【问题讨论】:

    标签: python numpy jupyter-notebook minimum indices


    【解决方案1】:

    使用np.where():

    np.where(q == q.min())[0]
    

    结果:

    array([1, 4])
    

    【讨论】:

      猜你喜欢
      • 2015-05-16
      • 2018-10-22
      • 2017-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-26
      • 2012-11-25
      相关资源
      最近更新 更多