I want to update a vector like this:
list = {0, 0, 0, 0};
updval = {1, 1, 1};
updind = {2, 2, 3};
list[[updind]] += updval;
list
The result is {0, 1, 1, 0}
, but should be {0, 2, 1, 0}
.
The problem are the repeated indices in updind
.
How can one do this correctly and fast?
The lists are on the order of kilobytes, but many such assignments need to be done.