[SciPy-user] Quick way to delete all 'values' from array
Gökhan SEVER
gokhansever at gmail.com
Tue Jul 14 11:07:17 EDT 2009
|
On Tue, Jul 14, 2009 at 9:56 AM, Adrian Price-Whelan
<adrian.prw at 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 at 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