Skip to main content
2 of 2
deleted 11 characters in body
kglr
  • 403.4k
  • 18
  • 501
  • 959

You can use SparseArray setting the system sub-option "TreatRepeatedEntries" to Plus:

SetSystemOptions["SparseArrayOptions" -> {"TreatRepeatedEntries" -> Plus}]; sa = SparseArray[{{1, 2} -> -1, {1, 1} -> 1, {1, 2} -> -1, {1, 6} -> 1}]; SetSystemOptions["SparseArrayOptions" -> {"TreatRepeatedEntries" -> First}]; Thread[sa@"NonzeroPositions" -> sa@ "NonzeroValues"] 

{{1, 2} -> -2, {1, 1} -> 1, {1, 6} -> 1}

kglr
  • 403.4k
  • 18
  • 501
  • 959