Initialization of array of arrays with `fill(ones(1),2,2)`: only one vector is created

Not really. After calling fill, it should always be the case that m[i] === m[j] because fill fills the array with the same (identical in every meaningful way in Julia) value.

A list comprehension like:

[ones(1) for _ in i:2, _ in 1:2]

is a common way to accomplish what you’re looking for. Alternatively, you can create a new array of arrays with Matrix{Vector{Float64}}(undef, 2, 2) and then fill it in a loop. Either solution should perform very well.

7 Likes