[Numpy-discussion] Advanced indexing advice
Cristi Constantin
darkgl0w at yahoo.com
Fri Jun 19 16:55:29 EDT 2009
Thank you very much Robert !
For really big matrices, "where" is 4 times faster ! For small matrices, it's slower than my old solution, but it really doesn't matter, it's fast enough. :)
I will think about "put" too. I used it before, but i must adapt all functions to obtain the necessary indexes.
Have a nice day !
From: Robert <kxroberto at googlemail.com>
Subject: Re: [Numpy-discussion] Advanced indexing advice?
To: numpy-discussion at scipy.org
Date: Friday, June 19, 2009, 6:49 AM
well its not really slow.
yet with np.where it seems to be 2x faster for large arrays :
a[1:4,1:4] = np.where(mask,b,a[1:4,1:4])
otherwise consider Cython:
http://docs.cython.org/docs/numpy_tutorial.html#tuning-indexing-further
Robert
> 2009/6/18 Cristi Constantin <darkgl0w at yahoo.com
> </mc/compose?to=darkgl0w at yahoo.com>>:
> > I have a question about advanced indexing.
> >
> > I have 2 matrices :
> >
> >>>>
> > a=array([[ 0, 1, 2, 3, 4, 5],
> > [ 6, 7, 8, 9, 10, 11],
> > [12, 13, 14, 15, 16, 17],
> > [18, 19, 20, 21, 22, 23]])
> >
> > b=array([[1, 0, 1],
> > [0, 2, 0],
> > [0, 0, 3]])
> >>>>
> >
> > I want to put all NON-zero elements from array B into array A,
> but use offset!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20090619/ce6f4284/attachment.html>
More information about the NumPy-Discussion
mailing list