Hi there,

In regards to a), I keep on getting the error message with the second option
> ERROR: type: apply: expected Function, got (Int64,Int64,Int64)
>

I'm guessing you accidentally redefined the symbol "tuple" to a tuple:

 julia> tuple(testtuple...,testvar)
(1,2,3,4)

julia> tuple = (1,2,3)
Warning: imported binding for tuple overwritten in module Main
(1,2,3)

julia> tuple(testtuple...,testvar)
ERROR: type: apply: expected Function, got (Int64,Int64,Int64)


For your second example, zip(tuplearray...) is actually about right.  The
main differences from what you want are

1) it returns an iterator, not a set of arrays
2) the iterator yields tuples, not arrays

julia> zip(tuplearray)
Zip{(Array{(Int64,Int64,Int64),1},)}(([(1,2,3),(10,20,30),(100,200,300)],))

julia> collect(zip(tuplearray...))
3-element Array{(Int64,Int64,Int64),1}:
 (1,10,100)
 (2,20,200)
 (3,30,300)

Cheers,
   Kevin


Just making sure, are you using 0.3? If so, hmm, I would be a bit stumped
> as to why the same line is not working for me.
>
> On Thursday, July 24, 2014 5:30:44 PM UTC-4, Leah Hanson wrote:
>
>> a) Your second option works for me:
>> ~~~
>> julia> testtuple = (1,2,3)
>> (1,2,3)
>>
>> julia> testvar = 4
>> 4
>>
>> julia> tuple(testtuple...,testvar)
>> (1,2,3,4)
>> ~~~
>>
>> b) I'm not sure what the cleanest code for your example would be, but
>> here's one possibility:
>>
>> ~~~
>> julia> tuplearray = [(1,2,3),(10,20,30),(100,200,300)]
>> 3-element Array{(Int64,Int64,Int64),1}:
>>  (1,2,3)
>>  (10,20,30)
>>  (100,200,300)
>>
>> julia> aarray = Int[]
>> 0-element Array{Int64,1}
>>
>> julia> barray = Int[]
>> 0-element Array{Int64,1}
>>
>> julia> carray = Int[]
>> 0-element Array{Int64,1}
>>
>> julia> for (a,b,c) in tuplearray
>>          push!(aarray,a)
>>          push!(barray,b)
>>          push!(carray,c)
>>        end
>>
>> julia> aarray
>> 3-element Array{Int64,1}:
>>    1
>>   10
>>  100
>>
>> julia> barray
>> 3-element Array{Int64,1}:
>>    2
>>    20
>>  200
>>
>> julia> carray
>> 3-element Array{Int64,1}:
>>    3
>>   30
>>  300
>> ~~~
>>
>> If would be faster to pre-allocate the arrays (to the length of the
>> tuplearray), and then just put the elements in at the correct indices, but
>> I'm not sure if that matters for your application.
>>
>> -- Leah
>>
>>
>>
>> On Thu, Jul 24, 2014 at 4:15 PM, <[email protected]> wrote:
>>
>>> Hi all,
>>>
>>> I thought to just add to my previous thread, but created a new one
>>> because the topic is a bit different. Hope y'all don't mind.
>>>
>>> Anyhow:
>>>
>>> a) How would I concatenate two tuples? Or a tuple with a variable?
>>>
>>> Say I have
>>>
>>> testtuple = (1,2,3)
>>> testvar = 4
>>>
>>> and want to get
>>>
>>> newtuple = (1,2,3,4)
>>>
>>> (not ((1,2,3),4)
>>>
>>> I've tried
>>> newtuple = tuple(testtuple...,testvar...)
>>> newtuple = tuple(testtuple...,testvar)
>>> newtuple = testtuple...,testvar
>>>
>>> but none of those have worked to produce the desired result.
>>>
>>> b) I have an array of tuples
>>>
>>> tuplearray = [(a1,b1,c1),(a2,b2,c2)...,(an,bn,cn)]
>>>
>>> How could I then unpack the array into
>>>
>>> aarray = [a1,a2...,an]
>>> barray = [b1,b2...,bn]
>>> carray = [c1,c3...,cn]
>>>
>>> such that each position in the tuple gets unpacked into a corresponding
>>> individual array?
>>>
>>> In Python, I would use
>>>
>>> alist,blist,clist = zip(*tuplelist)
>>>
>>> It appears that
>>>
>>> aarray,barray,carray = zip(tuplearray...)
>>>
>>> is not the Julia equivalent.
>>>
>>> My version of Julia is the .3 RC.
>>>
>>> Thanks for your help
>>>
>>
>>

Reply via email to