# Vector of MVectors

**URL:** https://discourse.julialang.org/t/vector-of-mvectors/128275
**Category:** General Usage
**Tags:** question, package, staticarrays
**Created:** [April 21, 2025, 10:03pm UTC](https://discourse.julialang.org/t/vector-of-mvectors/128275 "2025-04-21T22:03:27Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [April 21, 2025, 10:41pm UTC](https://discourse.julialang.org/t/vector-of-mvectors/128275/7 "2025-04-21T22:41:26Z")

</div>

> [@ufechner7](#):
>
> But the behavior shown in the first post is still unexpected. Can anybody explain what is going on there? Is that a bug?

It certainly seems like it would be friendlier for the `zeros` function to have a specialized implementation for `MVector`, but I’m not sure it’s a bug: your code is equivalent to `fill(zero(MVector{3, Float64}), 4)`, which only allocates a single `MVector` and re-uses it for all elements, which leads to what you saw if you mutate it. (You’d see the same problem if you tried `vec[1][1] = 3`.)

Do:

```julia
vec = [zero(MVector{3, Float64}) for _=1:4]

```

to ensure that each element of `vec` is a distinct `MVector`.

PS. See also [Current behavior of fill and the like..?](https://discourse.julialang.org/t/current-behavior-of-fill-and-the-like/78888) and many other discussions.

---

_[View the full topic](https://discourse.julialang.org/t/vector-of-mvectors/128275)._
