Ah, great thanks!
On Thursday, July 17, 2014 3:48:39 PM UTC+2, David Gonzales wrote:
>
> its possible to nest comprehensions:
> [ [x[y] for x in mytuple] for y=1:2 ]
> this expression can be splatted like you suggested.
>
> On Thursday, July 17, 2014 3:53:42 PM UTC+3, Tomas Lycken wrote:
>>
>> That's neat! Thanks!
>>
>> However, it only got me *almost* there - my next step was to use these
>> arrays as function arguments, so I want to use `...` splatting. However,
>> `foo([x[y] for x in mytuples,y=1:2]...)` will splat the entire matrix
>> element-wise, instead of row-wise.
>>
>> Is there a way to get it into two `Array{Float64,1}` objects, rather than
>> an `Array{Float64,2}`, and still only use it in one expression?
>>
>> (Yes, I realize I'm starting to make things more complicated than they
>> need to be, but this is an opportunity to learn new ways of doing things -
>> not just an attempt to get things done :P)
>>
>> // T
>>
>> On Thursday, July 17, 2014 2:05:38 PM UTC+2, David Gonzales wrote:
>>>
>>> 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
>>>>
>>>>
>>>