is there a way I can do something like, if

h = Table[i, {i, 0, 5, 1}]

so, I can access the 4th element of the h[[4]], so, what about going other way around that 3 is the fourth element.

  • 2
    $\begingroup$ PositionIndex[h]@3 or Position[h, 3]? $\endgroup$
    – kglr
    Feb 21 at 10:11

Position is actually a pretty useful function. Not only can it find specific values:

Position[h, 3]

(as suggested by kglr) but it can also be used to locate indices of ranges of values, for example:

Position[a, _?((2 < # < 5) &)]


Position[a, x_ /; (2 < x < 5)]

to locate all the indices with values between 2 and 5.


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.