Julia: append to an empty vector

I want to create an empty vector and append an array to Julia What do I do?

x = Vector{Float64}
append!(x,rand(10))

The result is

`append!` has no method matching append!(::Type{Array{Float64,1}},::Array{Float64,1})

thank you.

Solution

Your variable X does not contain an array, but does not contain a type

x = Vector{Float64}
typeof(x)  # DataType

You can create an array of array (float64, n) (but be careful, it is uninitialized: it contains any value) or zero (float64, n), where n is the desired size

Since float64 is the default value, we can discard it Your example becomes:

x = zeros(0)
append!( x,rand(10) )
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>