Disclaimer: this is explicit in the help entry of fill, so I am not complaining of anything…
julia> m = fill(ones(1),2,2)
2×2 Array{Array{Float64,1},2}:
[1.0] [1.0]
[1.0] [1.0]
julia> m[1,1][1] = 2
2
julia> m
2×2 Array{Array{Float64,1},2}:
[2.0] [2.0]
[2.0] [2.0]
Clearly ones(1)
was called only once and the vectors at all positions are the same.
Using fill(copy(ones(1)),2,2)
(this was more strange to me) also results in the same thing.
Is there, therefore, a simple syntax to use fill
to create an array of independent arrays?
4 posts - 3 participants