… I probably should not have been sloppy about the typing the 
comprehensions in my previous answer. I think this is probably better

julia> x = [1,2,3]
3-element Array{Int64,1}:
 1
 2
 3

julia> pairs_any = [[i,j] for i in x, j in x] |> vec
9-element Array{Any,1}:
 [1,1]
 [2,1]
 [3,1]
 [1,2]
 [2,2]
 [3,2]
 [1,3]
 [2,3]
 [3,3]

julia> pairs_int = Vector{eltype(x)}[[i,j] for i in x, j in x] |> vec
9-element Array{Array{Int64,1},1}:
 [1,1]
 [2,1]
 [3,1]
 [1,2]
 [2,2]
 [3,2]
 [1,3]
 [2,3]
 [3,3]

btw, I’m a bit puzzled what Array{Array{T,1},1} means when T is not 
defined. This is what I get when I did the sloppy version 

julia> pairs_T = Vector[[i,j] for i in x, j in x] |> vec
9-element Array{Array{T,1},1}:
 [1,1]
 [2,1]
 [3,1]
 [1,2]
 [2,2]
 [3,2]
 [1,3]
 [2,3]
 [3,3]

julia> T
ERROR: T not defined

On Thursday, June 19, 2014 12:49:21 PM UTC-7, Ethan Anderes wrote:

Comprehensions will give you what you want
>
> x = [1,2,3]
> pairs = Vector[[i,j] for i in x, j in x] |> vec
>
> On Thursday, June 19, 2014 12:16:32 PM UTC-7, paul analyst wrote:
>
> How to convert vector to a series of possible pairs of elements  ? 
>>
>> [1,2,3] 
>>
>> I expect 
>>
>> [1,1] [1,2] [1,3] [2,1] [2,2] [2,3] [3,1] [3,2] [3,3]
>>
>> ​
>
​

Reply via email to