Hi,
I would like to take a vector like:
julia> vector
5-element Vector{Float64}:
90.51
51.79
84.81
66.11
56.68
and output
"0"
"1:90.51"
"2:51.79"
"3:84.81"
"4:66.11"
"5:56.68"
that will be written into a file (using writedlm) as:
0 1:90.51 2:51.79 3:84.81 4:66.11 5:56.68
So I wrote and tested this:
using BenchmarkTools
vector=rand(.1:.01:100.99, 50000)
function to_svm(vec)
SVM_line=["0"]
index=0
for value in vec
index+=1
push!(SVM_line, string(index) * ":" * string(value))
end
return SVM_line
end
function to_svm_v2(vec)
SVM_line=["0"]
for iter in eachindex(vec)
push!(SVM_line, string(iter) * ":" * string(vec[iter]))
end
return SVM_line
end
@benchmark line=to_svm(vector)
@benchmark line_v2=to_svm_v2(vector)
The two methods take the same time, but Iβd like to know if thereβs a way to go faster. I have to process a lot of vector β lines before writing to the file so this is really the part of the code that Iβd like to optimize.