Say I have a list x={2,4,6,8,10}
and I want to find out the positions of the elements that are greater than 7.
Select[x, #>7&]
gives the elements themselves, and Position[x,8]
gives the position of the elements satisfying one of the possible criteria, but what I am looking for would be a mix of the two returning {4,5}
.
Any suggestions?
Pick
to enhance performance:x = {2, 4, 6, 8, 10}; Pick[Range[Length[x]], Sign[x - 6], 1]
. $\endgroup$PatternTest
rather thanCondition
. Are any performance differences or is it just what people are used to? $\endgroup$Condition
for ease of naming elements to work with them. $\endgroup${2, 4, 6, 8, 10} // Position[_?(GreaterThan[7])]
$\endgroup$