Many times I want to output a simple data table from a vector, like in this MWE:
julia> for i in 1:5
println(rand(3))
end
[0.6125928743733668, 0.36073254544716105, 0.5008360754548771]
[0.04295309867553865, 0.2695746137499093, 0.8300907403333446]
[0.583606126726895, 0.35685598691093867, 0.6457105731760235]
[0.2378687372009609, 0.9417391680121274, 0.7781190880491764]
[0.5099446049834098, 0.5874226809107426, 0.12270964644338145]
I would like to print that without the braces and the commas. Like this:
julia> for i in 1:5
x = rand(3)
for v in x
print("$v ")
end
print("\n")
end
0.2651120847888846 0.318163694284342 0.2106114829636947
0.2938839408544498 0.2645723271091036 0.993859969760363
0.0921973200585453 0.6385938138072869 0.13466907347686785
0.7716713510203739 0.2821766396139149 0.5727765718922624
0.31251479998055776 0.5274458513709515 0.8257634367657791
(most commonly to a file, but that is not the point).
Is there a one-liner simple notation for that? The problem is that this prints the generator instead of the actual data:
julia> x = rand(3)
println("$v " for v in x)
Base.Generator{Vector{Float64}, var"#1#2"}(var"#1#2"(), [0.5117878075322972, 0.7627506311079011, 0.5697925099293792])
and if I collect I get back to the original problem.
(now one related curiosity: an iterator like for v in x
guarantees that the elements will be iterated in the order of their indexes in x
?)