In numpy there is an efficient solution for generating the cartesian product of two vectors using meshgrid
.
Is there a ready-made solution for getting the combinations of all elements in a single vector as per {x_i, x_j : 1 <= i <= j <= N}
where N
is the length of the vector?
Illustration: Let us asume:
input = [1, 2, 3, 4]
Output should ideally be two vectors that together form the combination of all elements of the input:
output1 = [1, 1, 1, 2, 2, 3]
output2 = [2, 3, 4, 3, 4, 4]
I know how to implement this with python loops but I was looking for a faster solution.
Also: Does this form of combination have a name?