Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I realise that

Position[{2, 4, 8, 16, 32, 64}, 4]

will return

{{2}}

I would like to do something like this:

Position[{2, 4, 8, 16, 32, 64}, {4, 32, 64}]

and get

{{2}, {5}, {6}}

I have searched, but can't ind anything - I am clearly missing something obvious :/

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

Position takes a pattern as last argument. Therefore, the most direct way is

Position[{2, 4, 8, 16, 32, 64}, 4 | 32 | 64]

or

Position[{2, 4, 8, 16, 32, 64}, Alternatives @@ {4, 32, 64}]

if you have your numbers in a list.

share|improve this answer
    
Great - the latter is more useful for me - very simple question, I know - but hugely time saving! Many thanks :) –  martin Dec 30 '13 at 21:09
add comment

If you want them in the order listed there is the direct approach.

 Flatten[Position[{2, 4, 8, 16, 32, 64}, #], 1] & /@ {32, 64,4}

     ->     { {5}, {6}, {2} }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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