Is there a function in Julia that returns a copy of an array of the desired type, i.e. equivalent of numpys astype function ? I have an array of type "Any" and you want to convert it to a Float array. I tried:
new_array = Float64(array)
but i get the following error
LoadError: MethodError: `convert` has no method matching convert(::Type{Float64}, ::Array{Any,2}) This may have arisen from a call to the constructor Float64(...), since type constructors fall back to convert methods. Closest candidates are: call{T}(::Type{T}, ::Any) convert(::Type{Float64}, !Matched::Int8) convert(::Type{Float64}, !Matched::Int16) ... while loading In[140], in expression starting on line 1 in call at essentials.jl:56
I can simply write a function that goes through the array and returns a float value for each element, but I find it a bit strange if there is no built-in method for this.
arrays julia-lang
P4nd4b0b3r1n0
source share