![](/img/trans.png)
[英]How to find the index of an element in a list which is minimum in a sublist of that list in Python?
[英]Python - how to find numbers in a list which are not the minimum
我有一個列表S = [a[n],b[n],c[n]]
,對於n=0
,列表S
的最小值是值'a'
。 在知道最小值的情況下,如何選擇值b
和c
? 我正在編寫的代碼經過n
多次迭代,並且我想檢查循環中給定迭代的最小元素。
Python 2.7.3,32位。 numpy 1.6.2。 Scipy 0.11.0b1
如果可以將整個列表展平為一個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]])
也許你可以做類似的事情
S.sort()
S[1:3]
這就是你想要的嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.