SelectI

SelectI

SelectI[ list op value ] returns the positions of the elements of a list that satisfy a condition.

Usages

SelectI[ list op value ]

SelectI takes a comparison of a list with a value, such as L > 5, compares every element, and returns the positions (starting at 1) of the elements for which the comparison is not False. The comparison can use =, <>, <, <=, > and >=; the evaluating forms such as == and >> also work.

Example in out
The positions of the elements larger than 4. SelectI[ {5, 1, 8} > 4 ] {1, 3}
The positions of the elements equal to 2. SelectI[ {2, 3, 2} = 2 ] {1, 3}
The positions of the elements not equal to 2. SelectI[ {1, 2, 3} <> 2 ] {1, 3}
Use the positions to get the elements. L := {4, 9, 1, 7}
I := SelectI[L > 5]
r := L[[I]]
I = {2, 4}
r = {9, 7}
Compare two lists element by element. SelectI[ {1, 2, 3} >= {0, 3, 3} ] {1, 3}
No element satisfies the condition. SelectI[ {1, 2} > 5 ] {}
Details
  • Undecided comparisons are selected: SelectI[ {0, 1, a, 3} >= 2 ] gives {3, 4}, because a >= 2 cannot be decided. Use SelectStrictI to select only the elements that certainly satisfy the condition.
  • No comparison: SelectI[ {1, 2} ] gives {1, 2}.
Invalid input Result
SelectI[ 5 > 2 ] Left unevaluated: one side of the comparison must be a list.

See also: SelectStrictI, Select, FindI, Elm ([[ ]])