Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

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

$
0
0

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

Read full topic


Viewing all articles
Browse latest Browse all 2795

Latest Images

Trending Articles



Latest Images