How to find the position of the elements in an array by Python?

  • A+
Category:Languages

I have following array:

scores=[2.619,3.3, 9.67, 0.1, 6.7,3.2] 

And I wish to retrieve the elements which more than 5 by following code:

min_score_thresh=5 Result=scores[scores>min_score_thresh] 

Hence this will result me result:

[9.67, 6.7] 

Now i wish to get the positions of this two element which is my expected answer will be store in variable x:

x = [2,4]

Please share me ideas, thanks


scores = [2.619, 3.3, 9.67, 0.1, 6.7, 3.2]  min_score_thresh = 5  # score is 5 or higher result = []  # position in 'scores' list indx = []  for i, item in enumerate(scores):     if item > min_score_thresh:         result.append(item)         indx.append(i)  x = indx  print(result) print(x) 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: