How can I use the unique(a, 'rows') from MATLAB in Python? -


i'm translating stuff matlab python language.

there's command, unique(a), in numpy. since matlab program runs 'rows' command also, gives little different.

is there similar command in python or should make algorithm same thing?

assuming 2d array stored in usual c order (that is, each row counted array or list within main array; in other words, row-major order), or transpose array beforehand otherwise, like...

>>> import numpy np >>> = np.array([[1, 2, 3], [2, 3, 4], [1, 2, 3], [3, 4, 5]]) >>> array([[1, 2, 3],        [2, 3, 4],        [1, 2, 3],        [3, 4, 5]]) >>> np.array([np.array(x) x in set(tuple(x) x in a)]) # or "list(x) x in set[...]" array([[3, 4, 5],        [2, 3, 4],        [1, 2, 3]]) 

of course, doesn't work if need unique rows in original order.


by way, emulate unique(a, 'columns'), you'd transpose original array, step shown above, , transpose back.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -