[Numpy-discussion] Advanced indexing advice
Cristi Constantin
darkgl0w@yahoo....
Fri Jun 19 15:55:29 CDT 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@googlemail.com>
Subject: Re: [Numpy-discussion] Advanced indexing advice?
To: numpy-discussion@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@yahoo.com
> </mc/compose?to=darkgl0w@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.scipy.org/pipermail/numpy-discussion/attachments/20090619/ce6f4284/attachment.html
More information about the Numpy-discussion
mailing list