Skip to content

Permutations without repetition #1236

Answered by jpivarski
maxgalli asked this question in Q&A
Discussion options

You must be logged in to vote

Are you sure what you're looking for should be called "permutations"? It looks like you want the Cartesian product with the diagonal elements removed (see ak.cartesian).

Here's a way to get your desired output (up to the order, but I think the middle two are swapped):

>>> array = ak.Array(["a", "b", "c"])
>>> left, right = ak.unzip(ak.argcartesian([array, array], axis=0))
>>> left
<Array [0, 0, 0, 1, 1, 1, 2, 2, 2] type='9 * int64'>
>>> right
<Array [0, 1, 2, 0, 1, 2, 0, 1, 2] type='9 * int64'>
>>> different = (left != right)
>>> left[different]
<Array [0, 0, 1, 1, 2, 2] type='6 * int64'>
>>> right[different]
<Array [1, 2, 0, 2, 0, 1] type='6 * int64'>
>>> array[left[different]]
<Array ['a'

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@maxgalli
Comment options

maxgalli Jan 19, 2022
Maintainer Author

Answer selected by maxgalli
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants