t1 ={0, 1, 2, Log[6]/Log[2], 3, Log[12]/Log[2], 4, Log[24]/Log[2]}

I want to get the Position of the Integers. I can do it by

Flatten[Position[Length /@ t1, 0]]

to get the result {1,2,3,5,7}. How would I use IntegerQ here to get the same result?

  • 4
    $\begingroup$ Use Position[t1, <pattern>, 1] and find some way to use IntegerQ in a pattern (spoiler). $\endgroup$
    – Jason B.
    Mar 18 at 15:51

Note that


gives a vector consisting if Trues and Falses. So you want the Positions of all those that have True:

Flatten@Position[IntegerQ /@ t1, True]
  • 1
    $\begingroup$ Also Flatten@Position[t1, _Integer, 1] $\endgroup$
    – Bob Hanlon
    Mar 18 at 22:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.