[SciPy-user] Quick way to delete all 'values' from array

Gökhan SEVER gokhansever@gmail....
Tue Jul 14 10:07:17 CDT 2009


|


On Tue, Jul 14, 2009 at 9:56 AM, Adrian Price-Whelan
<adrian.prw@gmail.com> wrote:
>
> Hey --
>
> I'm just looking for the quickest way to remove all X from an array
> [a,b,c,d,X,e,X,f,gX] or it could be multidimensional, I suppose, but
> thats the idea. I understand delete() will remove a value at a
> specific index, but I was unsuccessful in combining this function with
> 'where' to get what I want. Any suggestions?
>
> Thanks,
> -Adrian
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user


This is my quickest solution with a list comprehension :

In [2]: a = array([1,2,3,4,6,5,6,7,8,6])

In [3]: a = array([a[i] for i in range(len(a)) if a[i] != 6])

In [4]: a
Out[4]: array([1, 2, 3, 4, 5, 7, 8])


--
Gökhan


More information about the SciPy-user mailing list