isnan

Ian Kelly ian.g.kelly at gmail.com
Tue Oct 12 12:22:35 EDT 2010


On Mon, Oct 11, 2010 at 11:47 PM, Andre Alexander Bell
<post at andre-bell.de>wrote:

> Hi Kenny,
>
> On 10/12/2010 05:58 AM, Kenny wrote:
> > I have an array A, and another one B with same dimention and size. Now I
> > want to change the delete the elements in A where the same position in B
> > is nan. How can I do.
> >
> > Similar to the matlab code A(find(isnan(B)) = []
>
> How about this:
>
> >>> from numpy import NAN
> >>> A = np.array([1,2,3,4,5])
> >>> B = np.array([NAN,2,3,NAN,NAN])
> >>> A = A[isnan(B)]
> >>> A
> array([1, 4, 5])
>

That's the inverse of what the OP wanted.  The full solution:

>>> A[~isnan(B)]
array([2, 3])

Cheers,
Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101012/61ed3bcd/attachment.html>


More information about the Python-list mailing list