I have a sparse matrix, and I am interested in find k largest elements and their positions in the matrix. I do it in the following manner:
matrix=SparseArray[Automatic, {4, 4}, 0, {
1, {{0, 2, 5, 8, 10}, {{2}, {3}, {1}, {3}, {4}, {1}, {2}, {4}, {2}, {
3}}}, {1.6608834828359216`, 1.3176250784021715`,
1.6608834828359216`, 3.8979590937707167`, 2.058499550409593,
1.3176250784021715`, 3.8979590937707167`, 1.0569052092863416`,
2.058499550409593, 1.0569052092863416`}}];
k = 2;
TakeLargest[Association@Most[ArrayRules[matrix]], k]
I look for a more efficient way to do it, any suggestion on how to speed up this calculation in huge matrices are welcome.