# Question about broadcasting

**URL:** <https://discourse.julialang.org/t/question-about-broadcasting/65989>\
**Category:** General Usage\
**Created:** [August 7, 2021, 2:44pm UTC](https://discourse.julialang.org/t/question-about-broadcasting/65989 "2021-08-07T14:44:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RJDennis](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@RJDennis](https://discourse.julialang.org/u/RJDennis)\
**Post date:** [August 7, 2021, 2:44pm UTC](https://discourse.julialang.org/t/question-about-broadcasting/65989/1 "2021-08-07T14:44:14Z")

</div>

Suppose I run the following

```julia
w = fill(zeros(3,3),3)
w[1] .= rand(3,3)

```

I expected the result would have the first matrix in `w` given random numbers with the remaining two matrices remaining zeros, but this is not the case. I know that if I simply do

`w[1] = rand(3,3)`

then I will get the answer I want, but I am going to be repeatedly updating the entries in `w` and I want to minimize allocations. What is the syntax to use broadcasting to update a single matrix in `w`?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [August 7, 2021, 2:46pm UTC](https://discourse.julialang.org/t/question-about-broadcasting/65989/2 "2021-08-07T14:46:21Z")

</div>

You want `w = [zeros(3,3) for _ in 1:3]`

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [August 7, 2021, 2:47pm UTC](https://discourse.julialang.org/t/question-about-broadcasting/65989/3 "2021-08-07T14:47:26Z")

</div>

> [@Threaded push! different for supposedly similar array initializations](https://discourse.julialang.org/t/threaded-push-different-for-supposedly-similar-array-initializations/65862/2):
>
> julia\> Y = fill(Int[],3); julia\> push!(Y[1], 9) 1-element Vector{Int64}: 9 julia\> Y 3-element Vector{Vector{Int64}}: [9] [9] [9] julia\> X = [Int[] for i=1:3] julia\> push!(X[1], 9) 1-element Vector{Int64}: 9 julia\> X 3-element Vector{Vector{Int64}}: [9] [] []
