Using Cases to pick out entries of a SparseArray
Here's a fast way if you have general values, like @ciao's:
SeedRandom[0];
sa = SparseArray[(# -> RandomChoice[Join[{x^2 + y^2, x^3}, Range@200]]) & /@
RandomInteger[{1, 2000}, {4000, 2}]];
Extract[sa["NonzeroPositions"],
Position[sa["NonzeroValues"], x^2 + y^2, 1]] // RepeatedTiming
{0.00015,
{{22, 1644}, {165, 37}, {207, 910}, {332, 291}, {354, 1432}, {997, 552},
{1211, 1944}, {1240, 1514}, {1505, 1421}, {1632, 899}, {1735, 702},
{1808, 1690}, {1816, 1445}, {1931, 1856}, {1934, 1709}, {1988, 312}}}
*)
If all values are numbers, then this is faster:
SeedRandom[0];
sa2 = SparseArray[# -> RandomInteger[{1, 200}] & /@
RandomInteger[{1, 2000}, {4000, 2}]];
Pick[sa2["NonzeroPositions"], sa2["NonzeroValues"], 1] // RepeatedTiming
(*
{0.0000261,
{{261, 1553}, {295, 1413}, {392, 1762}, {400, 1357}, {418, 850},
{580, 237}, {665, 1699}, {739, 1314}, {776, 1589}, {874, 206}, {932, 828},
{1215, 730}, {1636, 150}, {1770, 214}, {1815, 1922}, {1928, 676}}}
*)