I think you're expecting too much from writedlm/readdlm. I don't think
it is all that useful beyond 2D arrays of simple datatype. An array of
an array is not simple. What it seems to be doing write a string
representation of `a` to the file:
repr(a)
You can recover its meaning with eval(parse(repr(a)))
b = readdlm(joinpath(path,"text.txt"), '\n')
b = map(x->eval(parse(x)), b)
or
b= Array{Float32}[eval(parse(bb)) for bb in b]
However, it would be better, faster and safer to just a more powerful
file fromat like HDF5.jl.
On Mon, 2015-04-13 at 12:56, JKpie <[email protected]> wrote:
> ok, here is the example:
>
> a = Array{Float32}[]
> push!(a,[1 2 3])
> push!(a,[4 5 4])
> push!(a,[7 8 9])
> println(typeof(a))
> writedlm(joinpath(path,"text.txt"),a)
> b = readdlm(joinpath(path,"text.txt"))
> println(typeof(b))
> println(b[1,:])
>
> the result is:
>
> Array{Array{Float32,N},1}
> Array{Any,2}
> Any["Float32[1.0" 2.0 "3.0]"]
>
> and the same behawior here:
>
> a = {}
> push!(a,rand(5))
> push!(a,rand(3))
> push!(a,rand(7))
> println(typeof(a))
> writedlm(joinpath(path,"text.txt"),a)
> b = readdlm(joinpath(path,"text.txt"))
> println(typeof(b))
> println(b[1,:])
> println(typeof(b[1,1]))
>
>
> and the result:
>
> -
> -
> -
> -
>
>
> -
>
> -
>
> -
>
>
> cljs
>
>
>
> Array{Any,1}
> Array{Any,2}
> Any["[0.054008985630280115,0.8947273976690304,0.14961853234717193,0.999972895523733,0.8907801902141823]"]
>
> SubString{ASCIIString}
>
> in both cases I would like to have a method to write the data and next to
> read it and have it with the same structure and types
> (or just a function to process this substrings).
>
> J
>
>
>
> On Sunday, April 12, 2015 at 7:55:30 PM UTC+2, Mauro wrote:
>>
>> An example which can be copy-pasted would be helpful. M
>>
>> On Sun, 2015-04-12 at 16:47, JKpie <[email protected] <javascript:>>
>> wrote:
>> > Hi,
>> >
>> > I am new Julia coder (I started to learn Julia two weeks ago). I have a
>> > problem with writedlm and readdlm functions.
>> > I have an array of vectors:
>> >
>> > Vector Array{Float32,N},4
>> >
>> > When I try to save it using writedlm to txt file and next read that file
>> > using readdlm I obtain a matrix:
>> >
>> > Matrix Any, 4
>> >
>> > which contains four substrings like: "Float32[1,2,3..."
>> >
>> > so my question is: is there any simple way to convert that strings into
>> > arrays of floats?
>> >
>> > I also need to write and read files of Any type arrays which contains
>> float
>> > vectors of different lengths.
>> >
>> > Thank you very much for your help,
>> > J
>>
>>