New answers tagged

3

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, ...


0

This is unlikely to be efficient, due to the Complement, and it's quite possible that the very first operation we do on the array "unpacks" it, but here's one possibility. Let's suppose we have a sample array, array = SparseArray@RandomInteger[{0, 5}, {10, 10}]; array // MatrixForm We set a new background for this SparseArray by doing array1 = ...



Top 50 recent answers are included