简体   繁体   中英

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' . How do I select the values b and c given that I know the minimum? 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.

Python 2.7.3, 32-bit. Numpy 1.6.2. 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:

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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