如何在python多维列表中查找高于特定值的所有索引 [英] How to find all indices above a specific value in a python multidimensional list

查看:1578
本文介绍了如何在python多维列表中查找高于特定值的所有索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在python中有一个带有一些浮点值的二维列表.我想找出列表中所有高于特定值的元素的索引.

I have a two dimensional list in python with some floating point values. I want to find out indices of all the elements in the list which are above a specific value.

例如,在下面的2 x 4列表中(为方便起见,为整数):

For example, in a 2 x 4 list as below (integer for convenience):

100    200    100    250
125    100    250    100

我需要所有等于或大于200的值的索引.这些索引是[0] [1],[0] [3]和[1] [2].

I need the indices of all the values which are equal or above 200. These indices are [0][1], [0][3] and [1][2].

请在这方面提供帮助.

谢谢.

推荐答案

Numpy对此非常方便:

Numpy is quite handy for this:

>>> import numpy as np
>>> a = [[100, 200, 100, 250], [125, 100, 250, 100]]
>>> a=np.array(a)
>>> np.argwhere(a>=200)
      array([[0, 1],
             [0, 3],
             [1, 2]])

这篇关于如何在python多维列表中查找高于特定值的所有索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆