| Author |
Comment/Response |
Mats
|
11/27/06 9:58pm
Hello.
I'd like to iteratively build up a matrix from a list of assignments: {row,col}->val
The problem however is that the Part function won't handle lists...
What's the most elegant way to do this?
One method I thought of was to implement a function like so:
FoldPart[tensor_, list_] :=
Apply[Part, Join[{tensor}, list]]
But it gives an error when I try to do things like this:
FoldPart[{{1,2},{3,4}},{2,2}] = 5
A second method I thought of using a SparseArray and converting to a regular array, but I'm concerned about efficiency (e.g. Mathematica not hashing the patterns and giving O(log(n)) time rather than O(1) time per lookup).
While the second method is fine for my computations, I'd just like to know what the most elegant way to do this would be in general, since it might be important when writing more complex pieces of code...
Thank you,
Mats
URL: , |
|