0

When we use the SparseArray in such form:

SparseArray[{pos1,pos2}->{val}]

We know that we don't have duplication of positions in pos1 and pos2. I mean that we don't have two copies of {10,10} or {12,12}. But if we have Mathematica will replace val on position {12,12} by the next val with position {12,12}.

Question: how I can implement not replacing, but summation of the vals with the same positions?

Now I have a not efficient code without using SparseArray:

testk = ConstantArray[0, {Max[jK], Max[jK]}];
For[
  i = 1, i <= Length[jK], i++,
  testk[[iK[[i]], jK[[i]]]] = testk[[iK[[i]], jK[[i]]]] + sK[[i, 1]]
  ];

0 Answers0