I have a list of about 106 pairs, where each element of the pair is either -1, 0, or 1:
[
[ 0, 1],
[-1, -1],
[ 0, -1],
[ 1, 0],
...
]
I want to split these pairs into two groups (i.e. lists of pairs) according to whether the first element of the pair is -1 or not1.
Is there a way to do this efficiently with numpy?
Despite the terminology and notation I used above, I am in fact agnostic about the actual types of the pairs and the "lists" of pairs. Use whatever numpy or python data structure leads to the most efficient solution. (But no pandas, please.)
EDIT:
For example, if the initial list of pairs is
[
[ 0, -1],
[ 0, -1],
[ 1, -1],
[-1, -1],
[ 1, 0],
[-1, 1],
[-1, -1],
[ 0, 0],
[ 0, 1],
[-1, 0]
]
...an acceptable result would consist of the two lists
[
[-1, -1],
[-1, 1],
[-1, -1],
[-1, 0]
]
...and
[
[ 0, -1],
[ 0, -1],
[ 1, -1],
[ 1, 0],
[ 0, 0],
[ 0, 1]
]
The last two lists preserve the ordering of elements as they appeared in the original lists. This would be my preference, but it is not essential. For example, a solution consisting of
[
[-1, -1],
[-1, -1],
[-1, 0],
[-1, 1]
]
...and
[
[ 0, -1],
[ 0, -1],
[ 0, 0],
[ 0, 1],
[ 1, -1],
[ 1, 0],
]
...would also be acceptable.
1 In other words, all the pairs in one group should have -1 at their first position, and all the elements of the other group should have either 0 or 1 at their first position.