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

eat e.antero.tammi@gmail....
Mon Jan 30 08:37:43 CST 2012


Hi,

On Mon, Jan 30, 2012 at 4:22 PM, Fabien Lafont <lafont.fabien@gmail.com>wrote:

> Sorry to be boring but do you have any idea?
>
> I want to have an array with 2 columns and erase the entire line when
> it find a "nan" in the second column?
>
> Thx again,
>
> Fabien
>
> 2012/1/27 Fabien Lafont <lafont.fabien@gmail.com>:
> > Thx,
> >
> > I have another. First I expose my problem I have datas like that. Is
> > it possible to create an array with two columns and then do something
> > to erase the entire line(both time and points) where nan appears?
> >
> >
> > X(Time)     Points
> > 1                  5
> > 2                 nan
> > 3                  3
> > 4                  4
> > 5                 nan
> > ...
> >
>
I think you have got already many answers to tackle this, but perhaps an
example demonstrates the point:

In []: data_old
Out[]:
array([[  1.,   5.],
       [  2.,  nan],
       [  3.,   3.],
       [  4.,   4.],
       [  5.,  nan]])

In []: data_new= data_old[~isnan(data_old[:, 1])]

In []: data_new
Out[]:
array([[ 1.,  5.],
       [ 3.,  3.],
       [ 4.,  4.]])


My 2 cents,
-eat

> >
> > 2012/1/27 David Warde-Farley <wardefar@iro.umontreal.ca>:
> >> On Fri, Jan 27, 2012 at 06:48:45PM +0100, Fabien Lafont wrote:
> >>> And how can I remove a specific element designated by its position
> >>> numer? like remove(a[8]) for exemple.
> >>
> >> This is generally not something you want to be doing with NumPy arrays.
> NumPy
> >> arrays represent fixed blocks of memory, removing an element means
> >> reallocating the array and copying values before and after position 8
> is the
> >> only way.
> >>
> >> If a is one-dimensional, then np.concatenate(a[:8], a[9:]) will do the
> job,
> >> but if you are going to be frequently performing this kind of operation
> you
> >> will get better performance out of a plain Python list.
> >>
> >> David
> >> _______________________________________________
> >> SciPy-User mailing list
> >> SciPy-User@scipy.org
> >> http://mail.scipy.org/mailman/listinfo/scipy-user
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20120130/db87188d/attachment.html 


More information about the SciPy-User mailing list