Permutation / combination of elements of a matrix per row

Hi

I have created a M x N matrix from which I want to create all elements resulting from

i.e. if I have A = [ 11 12 13 14; 21 22 23 24; 31 32 33 34], I want to create:

[11; 21; 31] [11; 21; 32] [11; 21; 33] [11; 21; 34 ] [12; 21; 31] [12; 21; 32] [12; 21; 33] [12; 21; 34 ] …

I found

```B = collect(combinations(A, 4)) ````

but that is generating all permutations not only picking an element per row.

Any idea ?

Thanks

It seems that:

collect(Iterators.product(eachcol(A)…))

returns an iterator that will allow to go through tuples

I think you mean,

julia> vec( collect( Iterators.product(eachrow(A)...) ) )
64-element Array{Tuple{Int64,Int64,Int64},1}:
 (11, 21, 31)
 (12, 21, 31)
 (13, 21, 31)
 (14, 21, 31)
 (11, 22, 31)
 (12, 22, 31)
 (13, 22, 31)
 (14, 22, 31)
 (11, 23, 31)
 (12, 23, 31)
 (13, 23, 31)
 (14, 23, 31)
 (11, 24, 31)
 ⋮
 (11, 22, 34)
 (12, 22, 34)
 (13, 22, 34)
 (14, 22, 34)
 (11, 23, 34)
 (12, 23, 34)
 (13, 23, 34)
 (14, 23, 34)
 (11, 24, 34)
 (12, 24, 34)
 (13, 24, 34)
 (14, 24, 34)

Or, if you like piping,
Iterators.product(eachrow(A)...) |> collect |> vec

1 Like