Is there any function in numpy to group this array down below by the first column?
I couldn't find any good answer over the internet..
>>> a
array([[ 1, 275],
[ 1, 441],
[ 1, 494],
[ 1, 593],
[ 2, 679],
[ 2, 533],
[ 2, 686],
[ 3, 559],
[ 3, 219],
[ 3, 455],
[ 4, 605],
[ 4, 468],
[ 4, 692],
[ 4, 613]])
Wanted output:
array([[[275, 441, 494, 593]],
[[679, 533, 686]],
[[559, 219, 455]],
[[605, 468, 692, 613]]], dtype=object)
Inspired by Eelco Hoogendoorn's library, but without his library, and using the fact that the first column of your array is always increasing.
I didn't "timeit" but this is probably the faster way to achieve the question :
PS: I wrote a similar line because I needed to "group by" the results of np.nonzero: