it is possible to use two indices in a comprehension:
    mat = [x[y] for x in mytuples,y=1:2]
now mat[:,1] is your first vector, and mat[:,2] is the second.

On Thursday, July 17, 2014 12:37:20 PM UTC+3, Tomas Lycken wrote:
>
> I have an array of 2-tuples of floats, created as
>
> julia> mytuples = (Float64,Float64)[(v.x, v.y for v in vs] # slightly more 
> complicated in actual code
> 136-element Array{(Float64,Float64),1}:
>  (4.0926,-2.55505)   
>  (4.170826,-2.586752)
>
> ...
>
> Now, I’d like to split this into two arrays of floats. I was under the 
> impression that zip could do this for me - according to the docs, zip is 
> its own inverse 
> <http://docs.julialang.org/en/latest/stdlib/base/#Base.zip>, and the 
> array of tuples does look like something I could get from zipping two 
> arrays. So I tried something similar to the example there:
>
> julia> julia> [zip(mytuples...)...]
> 2-element Array{(Float64,Float64,Float64, ... and so on, 136 times...),1}:
>
> so I guess that only works on actual Zip objects, and not on arrays (that 
> could have been) generated by the zip function inside []. (Also, since 
> this uses splatting with ... on large lists, it might not be a good idea 
> in the first place…? 
> <https://github.com/JuliaLang/julia/issues/6098#issuecomment-37203821>)
>
> What’s the best way to accomplish what I want, i.e. transforming the 
> mytuple variable above into two Vector{Float64}s (possibly inside a tuple 
> or array or something)?
>
> // T
> ​
>

Reply via email to