0
$\begingroup$

I have a list for which I want to extract the position at which pi occurs as follows:

fixed\[Phi]values = {0, \[Pi]/2, \[Pi], (3 \[Pi])/2};
Position[fixed\[Phi]values, \[Pi]]

When I run this, however, I get the nonsense answer

{{2, 2}, {3}, {4, 2}}

when I clearly should be getting

{3}

How do I correct this? Thanks in advance for any help.

$\endgroup$

1 Answer 1

5
$\begingroup$

The documentation for Position clearly shows that it searches at every level and inside every subexpression.

If you want it to only look at the topmost level then perhaps telling it to only look for this at the first level might be closer to what you are looking for.

fixedφvalues = {0, π/2, π, (3 π)/2};
Position[fixedφvalues, π,{1}]
(*{{3}}*)
$\endgroup$

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