Suppose I have a zero matrix Amat
and a list of values ltest
that contains the values of the matrix Amat
for the some of its diagonal elements:
L = 10000;
Amat = 0. IdentityMatrix[L];
ltest = {{-0.70710, 1329}, {-0.25, 5607}, {-0.3535, 1261}, {-0.25, 4393}, {-0.5, 4358},
{-0.3511, 1009}, {-1., 3815}, {-0.25, 3784}, {-0.133, 3667}, {-0.88, 909}};
Now in order to pass the second column of ltest
to Amat
I can do:
For[i = 1, i <= Length[ltest], i++, Amat[[ltest[[All, 2]][[i]], ltest[[All, 2]][[i]]]] = ltest[[All, 1]][[i]]]
Is there a shorter way without using For
?
SparseArray[]
? $\endgroup$ – J. M.'s ennui♦ Jan 26 at 12:18