I make a list of 5 empty $3 \times 3$ matrices via


However when I want to change an entry via


I get an error which reads:

Set::setps: m[2] in the part assignment is not a symbol. >>

Any ideas? Thanks

  • 2
    $\begingroup$ Why not do something like m = ConstantArray[0, {5, 3, 3}] and then do m[[2, 3, 4]] = 1? $\endgroup$ Mar 30, 2017 at 5:37
  • $\begingroup$ You mean instead of explicitly indexing the matrices, placing them in a list and identifying them there. That does make the way I call the matrices a little more intuitive, I don't have the single brackets and then the double brackets. However, I'm curious why indexing the matrices directly messes with the assignment I make. $\endgroup$
    – Mike
    Mar 30, 2017 at 5:40
  • 1
    $\begingroup$ The docs for the error message just says "Part assignments are implemented only for parts of the value of a symbol." So since m[2] is not a symbol itself, but a reference to one of the DownValues of the symbol m, this is what you get. $\endgroup$ Mar 30, 2017 at 5:42
  • $\begingroup$ Also, note the difference between Do and Table, we don't use Table just for side effects ;) $\endgroup$ Mar 30, 2017 at 5:43
  • 2
    $\begingroup$ You can do e.g. m[2] = ReplacePart[m[2], {3, 4} -> 5] but that copies the whole of m[2] so I would prefer @J.M. 's suggestion. $\endgroup$ Mar 30, 2017 at 5:49

1 Answer 1


As the comments read, the problem is that m[2] is not a symbol but a reference to a value of the symbol m, so to change the value there I have to actually replace it via:


Which copies the entirety of m[2] and doesn't look all that pretty.

J.M.'s suggestion is to just make a list of the matrices and refer to them from there.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.