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

iphone - Using nested NSDictionary with Picker -

php - accessing mysql using different server to which db connection data is located -

javascript - Iterate over array and calculate average values of array-parts -