2

I have a list a, which consists of some positive real numbers. I want to find the indices of elements which are larger than 10 in list a, and put the indices into another list index. The following is my code:

a = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19};
index = {};
For[i = 1, i <= Length[a], i++,
 If[a[[i]] > 10, index = Append[index, i]]
]
index

The output is

{6, 7, 8, 9, 10}

which is correct. Is there a better way to find the list index? For example, do not use the For loop. Thank you very much in advance.

Wei-Cheng Liu
  • 439
  • 4
  • 10

1 Answers1

2

You could use Pick and UnitStep as follows:

index = Pick[Range[Length[a]], UnitStep[10 - a], 0]
KennyColnago
  • 15,209
  • 26
  • 62