[英]Python - how to find numbers in a list which are not the minimum
I have a list S = [a[n],b[n],c[n]]
and for n=0
the minimum of list S
is the value 'a'
. 我有一个列表S = [a[n],b[n],c[n]]
,对于n=0
,列表S
的最小值是值'a'
。 How do I select the values b
and c
given that I know the minimum? 在知道最小值的情况下,如何选择值b
和c
? The code I'm writing runs through many iterations of n
, and I want to examine the elements which are not the minimum for a given iteration in the loop. 我正在编写的代码经过n
多次迭代,并且我想检查循环中给定迭代的最小元素。
Python 2.7.3, 32-bit. Python 2.7.3,32位。 Numpy 1.6.2. numpy 1.6.2。 Scipy 0.11.0b1 Scipy 0.11.0b1
If you can flatten the whole list into a numpy array, then use argsort, the first row of argsort will tell you which array contains the minimum value: 如果可以将整个列表展平为一个numpy数组,请使用argsort,argsort的第一行将告诉您哪个数组包含最小值:
a = [1,2,3,4]
b = [3,-4,5,8]
c = [6,1,-7,12]
S = [a,b,c]
S2 = np.array(S)
S2.argsort(axis=0)
array([[0, 1, 2, 0],
[1, 2, 0, 1],
[2, 0, 1, 2]])
Maybe you can do something like 也许你可以做类似的事情
S.sort()
S[1:3]
This is what you want? 这就是你想要的吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.