I got a real array A
, where Dimensions[A] == {5000, 5000, 5}
.
Some of the values in A
are -1
, others are not.
How can I use Position[]
to find the indices of those values which are not -1
?
Answer
A = Table[If[Round@# == -1, -1, #] &[RandomReal[{-2, 0}]], {5}, {5}]
{{-1, -1.85034, -0.063618, -1.97166, -1.98232},
{-1, -0.407057, -1.72254, -1.5231, -1.99315},
{-1, -1, -1, -1.98979, -1},
{-1, -1, -0.134094, -1.92523, -1.90799},
{-0.304344, -1, -1, -1.91487, -1.66092}}
SparseArray[A, Automatic, -1]["NonzeroPositions"]
{{1,2}, {1,3}, {1,4}, {1,5}, {2,2}, {2,3}, {2,4}, {2,5}, {3,4}, {4,3}, {4,4}, {4,5}, {5,1}, {5,4}, {5,5}}
Comments
Post a Comment