i have long vecotr od srings, dane[:,5]
12245198 -element Array{Any,1}:
“aa”
“ac”
“…”
“ab”
“aa”
saved by
writecsv(“file.txt”,string.(dane[:,5]))
is only ±33 000 KB
but saved by
`file = jldopen(“file.jld”,“w”)
close(file)
file = jldopen(“file.jld”,“r+”)
@time write(file,“user”,string.(dane[:,5]))
close(file)`
created file over 40 000 000 KB !!! What wrong ? How to optymaly this vector to save in JLD ? …as string.
Paul
mauro3
September 24, 2017, 8:23am
2
Try JLD2? Also please quote code with
` and blocks of code with ```
.
Also, if each element of that array
contains only ASCII characters,
has uniform length, or variable length that can be bounded by a small number,
then Matrix{UInt8}
is also a viable choice.
If the strings repeat a lot, you could collect them and index into it. See for example
https://github.com/JuliaComputing/PooledArrays.jl
Yes, JLD2 make to lage file also!
Paul
What happens if you convert the array to actually be of type Vector{String}
instead of Vector{Any}
?
Thanks, convert(Array{String},a) with JLD working better!
BUT, if i Have vector “a” {Any} like below. In this case is npossible to make CONVERT(…
If i am using string.(a) the saved data are huge:/
What to do ?
Paul
julia> a
2-element Array{Any,1}:
123456
“ABCDEF”
julia> string.(a)
2-element Array{String,1}:
“123456”
“ABCDEF”
julia> convert(Array{String},a)
ERROR: MethodError: Cannot convert
an object of type Int64 to an object of type String
This may have arisen from a call to the constructor String(…),
since type constructors fall back to convert methods.
in copy!(::Base.LinearFast, ::Array{String,1}, ::Base.LinearFast, ::Array{Any,1}) at .\abstractarray.jl:559
in convert(::Type{Array{String,N}}, ::Array{Any,1}) at .\array.jl:235
I have !
convert(Array{String},string.(a))
string.(a)
doesn’t modify a
, it returns a new array.
1 Like