How to load a CSV file with complex numbers in julia?

I am trying to access some complex numbers that I wrote to a csv file in julia, but I am having trouble recognizing it. To understand what is happening, consider the following

a = [1+2.3im, 2.3+0im] writecsv("test.csv",a) b = readcsv("test.csv") 

Now, if I interrogate types

 julia> typeof(b) Array{Any,2} julia> typeof(a) Array{Complex{Float64},1} 

And I cannot use b elements as complex numbers, as a string. ( b[1] is "1.0 + 2.3im" , for example).

+7
csv julia-lang
source share
1 answer

Here is one way:

 julia> b = map(x->eval(parse(x)),readcsv("test.csv")) 2x1 Array{Complex{Float64},2}: 1.0+2.3im 2.3+0.0im 
+8
source share

All Articles