[SciPy-user] Delete equal elements from array

Francesc Alted faltet at pytables.org
Tue Feb 17 02:57:44 EST 2009


A Tuesday 17 February 2009, Sahar Vilan escrigué:
> Hi,
>
> I have to exclude equal elements from an array.
> x1 = np.array([1, 4, 5, 5])
>
> Is there any function to get from x1 an array with one element of
> each kind ( [1, 4, 5, 5] -> [1, 4, 5])?

Yes.  Try np.unique (or np.unique1d, depending on your needs):

In [2]: x1 = np.array([1, 4, 5, 5])

In [3]: np.unique(x1)
Out[3]: array([1, 4, 5])

Cheers,

-- 
Francesc Alted



More information about the SciPy-User mailing list