How do I assign a value, say 7 or "t", to a[1, 2][[3]]
?
a[1, 2][[3]] = 7
and
a[1, 2][[3]] = "t"
both give
Set::setps: a[1,2] in the part assignment is not a symbol
I have looked here and here, but both questions ask more complicated questions and I'm afraid I'm none the wiser.
a[1, 2] = MapAt[7 &, a[1, 2], {3}]
ora[1,2] = ReplacePart[a[1, 2], 3 -> 7]
? $\endgroup$MapAt
orRepalcePart
will reassign entire list. Note also thata[1,2][3]
is a completely different thing - it is a nested indexed variable, whilea[1,2][[3]]
is a part3
of the value of indexed variablea[1,2]
. $\endgroup$DownValues
orSubValues
), which are rule-based. This is why this kind of complex part assignments are not allowed there. You can use an association instead, where you will be able to do something similar to what you want. $\endgroup$a[1,2,3] = 7
, you don't define an array. Instead, you define an indexed variable. They are different objects. To define an array, you need to useList
, likea = {{{1,2,3}, {4,5,6}}, {{7,8,9},{10,11,12}}}
, which is a 3D array. Then you can doa[[1,2,3]] = 7
, and that would replace the number6
in that array by7
. But you must have an array stored in some variable first, to make such part assignments. $\endgroup$