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.

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

100 200 100 250

125 100 250 100

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

Please help in this regards.

Thank you.

解决方案

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]])

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值