简体   繁体   English

在 arrays 的列表中查找最小值的索引

[英]Finding the index of the minimum value in a list of arrays

Let's say I have a list with multiple arrays:假设我有一个包含多个 arrays 的列表:

L = [
  array([-10, -8, -3, 2, 1]),
  array([-9, -4, -1, 3, 5]),
  array([-11, -5, -4, 0, 10])
]

How can I find the index of the lowest value the most efficiently?如何最有效地找到最低值的索引?

For my example, the minimum value is -11 and the index is (2, 0), so the output should be (0, 2).对于我的示例,最小值为 -11,索引为 (2, 0),因此 output 应为 (0, 2)。

What about the following?那么以下呢?

import numpy as np将 numpy 导入为 np

L = [
  np.array([-10, -8, -3, 2, 1]),
  np.array([-9, -4, -1, 3, 5]),
  np.array([-11, -5, -4, 0, 10])
]

L_2d = np.array(L)

min_index = np.unravel_index(L_2d.argmin(), L_2d.shape)
(min_index[0], min_index[1])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM