I'm trying to write a program that takes a given matrix A
of 1
's and 0
's and flips a designated amount of 1
's to -1
's.
lis1 = ArrayRules[A];
For[i = 1, i < Length[lis1] , i++
lis2 = RandomChoice[ArrayRules[A], n];
{a, b} = lis2[[i]];
ReplacePart[lis1, {a,b} -> -1];
This obviously doesn't work, and I'm not sure I even need the For
loop for this, but what syntax do I need specifically to replace the [i,j]
element of lis1
with -[i,j]
of lis2
?
Is there a more efficient way of doing this?
ReplacePart[list1, {##} -> -list2[[##]]] & @@@ {{i1, j1}, {i2, j2}}
? $\endgroup$