arrays - Identify vectors with same value in one column with numpy in python -


i have large 2d array of vectors. want split array several arrays according 1 of vectors' elements or dimensions. receive 1 such small array if values along column consecutively identical. example considering third dimension or column:

orig = np.array([[1, 2, 3],                   [3, 4, 3],                   [5, 6, 4],                   [7, 8, 4],                   [9, 0, 4],                   [8, 7, 3],                   [6, 5, 3]]) 

i want turn 3 arrays consisting of rows 1,2 , 3,4,5 , 6,7:

>>> array([[1, 2, 3],        [3, 4, 3]])  >>> b array([[5, 6, 4],        [7, 8, 4],        [9, 0, 4]])  >>> c array([[8, 7, 3],        [6, 5, 3]]) 

i'm new python , numpy. appreciated.

regards mat

edit: reformatted arrays clarify problem

using np.split:

>>> a, b, c = np.split(orig, np.where(orig[:-1, 2] != orig[1:, 2])[0]+1)  >>> array([[1, 2, 3],        [1, 2, 3]]) >>> b array([[1, 2, 4],        [1, 2, 4],        [1, 2, 4]]) >>> c array([[1, 2, 3],        [1, 2, 3]]) 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -