Weird behavior assigning values to initialized vector of matrices?

This is basically the same as the recent thread: Current behavior of fill and the like..?

The explanation of this behavior is already included in the documentation of fill!:

help?> fill!
search: fill! fill finally findall

fill!(A, x)

Fill array A with the value x. If x is an object reference, all elements will refer to the same object. fill!(A, Foo()) will return A filled with the result of evaluating Foo() once.

If you want to initialize something creating multiple distinct objects instead of using always the same, either use an array comprehension or map(copy, ...) as it is suggested in that thread. In your specific case, as the container already exist, maybe the best solution is V .= copy.(value).

2 Likes