[SciPy-User] [scipy-user] How to remove a value from an np array?

Fabien Lafont lafont.fabien at gmail.com
Fri Jan 27 12:48:45 EST 2012


And how can I remove a specific element designated by its position
numer? like remove(a[8]) for exemple.

thx

Fabien

2012/1/27 russel <russel at appliedminds.com>:
> In [12]: a=np.arange(10)
>
> In [13]: b=np.ones((10,))
>
> In [14]: b[[3,4,7,8]] = np.nan
>
> In [15]: a
> Out[15]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>
> In [16]: b
> Out[16]: array([  1.,   1.,   1.,  nan,  nan,   1.,   1.,  nan,  nan,   1.])
>
> In [17]: nans = np.isnan(b)
>
> In [18]: a[~nans]
> Out[18]: array([0, 1, 2, 5, 6, 9])
>
> In [19]: b[~nans]
> Out[19]: array([ 1.,  1.,  1.,  1.,  1.,  1.])
>
>
>
> On 01/27/2012 08:56 AM, Fabien Lafont wrote:
>> thanks a lot. Is there a way to do so but acting on elements array? I
>> explain you why. I have a vector with some 'nan' elements. I want to
>> remove them and to know the position on the array to remove another
>> element on another array but at the same 'place(position number)'
>>
>>
>> 2012/1/27 Warren Weckesser<warren.weckesser at enthought.com>:
>>>
>>>
>>> On Fri, Jan 27, 2012 at 10:49 AM, Fabien Lafont<lafont.fabien at gmail.com>
>>> wrote:
>>>>
>>>> I have that [3,2,4,8,7,8,9] and I want [3,2,8,7,8] how can I do?  I've
>>>> tried remove() but it works only on lists not on np.array.
>>>
>>>
>>>
>>> In [21]: a = array([3,2,4,8,7,8,9])
>>>
>>> In [22]: b = a[(a != 4)&  (a != 9)]
>>>
>>> In [23]: b
>>> Out[23]: array([3, 2, 8, 7, 8])
>>>
>>>
>>> Warren
>>>
>>>
>>> _______________________________________________
>>> SciPy-User mailing list
>>> SciPy-User at scipy.org
>>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>>
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User at scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user



More information about the SciPy-User mailing list