# Weird behavior assigning values to initialized vector of matrices?

**URL:** <https://discourse.julialang.org/t/weird-behavior-assigning-values-to-initialized-vector-of-matrices/79128>\
**Category:** New to Julia\
**Tags:** array, arrays\
**Created:** [April 6, 2022, 10:07pm UTC](https://discourse.julialang.org/t/weird-behavior-assigning-values-to-initialized-vector-of-matrices/79128 "2022-04-06T22:07:57Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [April 6, 2022, 10:19pm UTC](https://discourse.julialang.org/t/weird-behavior-assigning-values-to-initialized-vector-of-matrices/79128/2 "2022-04-06T22:19:06Z")

</div>

This is basically the same as the recent thread: [Current behavior of fill and the like..?](https://discourse.julialang.org/t/current-behavior-of-fill-and-the-like/78888)

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)`.

---

_[View the full topic](https://discourse.julialang.org/t/weird-behavior-assigning-values-to-initialized-vector-of-matrices/79128)._
