Here is a simple list:
l={1, 0, 2, 1, 0, 1, 0, 1, 2, 0, 2, 0, 1, 0, 1, 0, 0}
To get the position of non-zero elements I use Position
with Except
:
Position[l,Except[0]]
Mathematica 9.0.1 returns
{{0}, {1}, {3}, {4}, {6}, {8}, {9}, {11}, {13}, {15}, {}}
I can't figure out why the first element is {0}
and the last one is {}
. If I use Cases
it works as expected:
Cases[l,Except[0]]
{1, 2, 1, 1, 1, 2, 2, 1, 1}
What am I missing here?