How do I change the data type of a Julia array from "Any" to "Float64"? How do I change the data type of a Julia array from "Any" to "Float64"? arrays arrays

How do I change the data type of a Julia array from "Any" to "Float64"?


Use convert. Note the syntax I used for the first array; if you know what you want before the array is created, you can declare the type in front of the square brackets. Any just as easily could've been replaced with Float64 and eliminated the need for the convert function.

julia> a = Any[1.2, 3, 7]3-element Array{Any,1}: 1.2 3   7  julia> convert(Array{Float64,1}, a)3-element Array{Float64,1}: 1.2 3.0 7.0


You can also use the broadcast operator .:

a = Any[1.2, 3, 7]Float64.(a)


You can use:

new_array = Array{Float64}(array)