I am trying to return a list of indices for elements within another list that pass some sort of rule (as fast as possible). Currently I am doing:
Elementspassed=[elem for elem in Mylist if point > elem]
for x in Elements passed:
newlist.append( Mylist.index(x) )
Mylist[Mylist.index(x)]=[]
I want to incorporate the for loop into the previous line. I am working with extremely large matrices and this current code takes too long. I am interested in the Elementspassed matrix just to be a list of indices in which point>elem rather than the two step process i am taking.
For example:
(for points > 33)
Now: Elementspassed=[34, 35, 34, 52, 51]
newlist=[0, 3, 4, 5, 6]
Want: Elementspassed=[0, 3, 4, 5, 6]
Elementspassed=[elem for elem in Mylist if point > elem]
for x in Elements passed:
newlist.append( Mylist.index(x) )
Mylist[Mylist.index(x)]=[]
I want to incorporate the for loop into the previous line. I am working with extremely large matrices and this current code takes too long. I am interested in the Elementspassed matrix just to be a list of indices in which point>elem rather than the two step process i am taking.
For example:
(for points > 33)
Now: Elementspassed=[34, 35, 34, 52, 51]
newlist=[0, 3, 4, 5, 6]
Want: Elementspassed=[0, 3, 4, 5, 6]
Comment