Given an np.arange(k)
for any integer k
value, I'm trying to find all its (k - 1)
-combinations.
Example with k = 4
(ideally by this order):
array([[1, 2, 3],
[0, 2, 3],
[0, 1, 3],
[0, 1, 2]])
Using regular python, this works:
[[j for j in range(k) if i != j] for i in range(k)]
But I was aiming for a more numpythonic approach. This is my best shot so far:
np.rot90(np.arange(k).repeat(k - 1).reshape((k - 1, k)))
Is there a cleaner way of doing it using numpy, or should I just use normal python?