Mizzle
Mizzle

Reputation: 757

How to copy an array in Julia 1.0

My code is below.

V = ntuple(x -> zeros(5, 5), 2)    
V1 = rand(5,5)    
copy!(V[1], V1)

I would like to replace all the values in V[1] by V1. copy! works well in Julia 0.6.3. However, it doesn't work in Julia 1.0.1.

Error message: MethodError: no method matching copy!(::Array{Float64,2}, ::Array{Float64,2})

I really appreciate your help.

Upvotes: 1

Views: 1327

Answers (1)

Dinari
Dinari

Reputation: 2557

Use .=:

V = ntuple(x -> zeros(5, 5), 2)
V1 = rand(5,5)
V[1] .= V1

It will make a copy of the values of V1 in V[1].

Upvotes: 3

Related Questions