[Numpy-discussion] Advanced indexing advice?
Good day. 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! This is how i did: mask = b!=0 # Save all non-zero values from B. offset = (1,1) # Save offset. bshape = b.shape # Save shape of B. # Action ! a[ offset[0]:bshape[0]+offset[0], offset[1]:bshape[1]+offset[1] ][ mask ] = b[ mask ] After this, a becomes : array([[ 0, 1, 2, 3, 4, 5], [ 6, 1, 8, 1, 10, 11], [12, 13, 2, 15, 16, 17], [18, 19, 20, 3, 22, 23]]) That's exactly what i want. Now, my method works, but is very slow when used with big arrays. I use doule indexing, one for offset and one for mask... Can anyone suggest another method, maybe with advanced indexing to do both the offset and the mask ? I am quite newbie with Numpy. Or maybe just don't use the mask at all ? All non-zero values from B must be inserted into A, using offset... I tried : a[ offset[0]:bshape[0]+offset[0], offset[1]:bshape[1]+offset[1], mask ] = b[ mask ] and a[ mask, offset[0]:bshape[0]+offset[0], offset[1]:bshape[1]+offset[1] ] = b[ mask ] but both methods transform a into : array([[ 1, 1, 1, 3, 4, 5], [ 6, 2, 8, 9, 10, 11], [12, 13, 3, 15, 16, 17], [18, 19, 20, 21, 22, 23]]) and that's completely wrong. Any advice is good. Thank you in advance. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Advanced indexing advice?
Hi Cristi 2009/6/18 Cristi Constantin darkg...@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! Here's a solution using views: offset = np.array([1,1]) slices = [slice(*x) for x in zip(offset, offset + b.shape)] c = a[slices] mask = (b != 0) c[mask] = b[mask] Regards Stéfan ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Interleaved Arrays and
Most excellent solutions, thanks! ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Advanced indexing advice?
Thank you so much for your prompt answer, Stéfan. It's a very very interesting method. I will keep it for future. :) But, i tested it with a few examples and the speed of execution is just a tiny bit slower than what i told you i was using. So it's not faster, it's about the same speed. Thank you again. I will play with your method a little more. --- On Thu, 6/18/09, Stéfan van der Walt ste...@sun.ac.za wrote: From: Stéfan van der Walt ste...@sun.ac.za Subject: Re: [Numpy-discussion] Advanced indexing advice? To: Discussion of Numerical Python numpy-discussion@scipy.org Date: Thursday, June 18, 2009, 2:16 AM Hi Cristi 2009/6/18 Cristi Constantin darkg...@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! Here's a solution using views: offset = np.array([1,1]) slices = [slice(*x) for x in zip(offset, offset + b.shape)] c = a[slices] mask = (b != 0) c[mask] = b[mask] Regards Stéfan ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Please add Mac binary for numpy 1.3.0 and Python 2.6
If you don't want to build one then you are welcome to serve one I built. Several people have tried it and reported that it works. Contact me for a URL. -- Russell ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Windows build-slave needed: please help out!
Hi everyone, Thomas Heller was kind enough to host our Windows build-slave thus far, but he can no longer do so. We need a new home for the Windows build slave, so if you have a Windows machine that is permanently on-line and that does not contain mission-critical data, please give me a shout. Thanks! Stéfan ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Windows build-slave needed: please help out!
Hi, Stefan. I was just thinking about the computer I'd designate for this, and remembered that I still have it running XP Pro and don't want to upgrade it to Vista, so there's that to consider. DG --- On Thu, 6/18/09, Stéfan van der Walt ste...@sun.ac.za wrote: From: Stéfan van der Walt ste...@sun.ac.za Subject: [Numpy-discussion] Windows build-slave needed: please help out! To: Discussion of Numerical Python numpy-discussion@scipy.org Date: Thursday, June 18, 2009, 2:19 PM Hi everyone, Thomas Heller was kind enough to host our Windows build-slave thus far, but he can no longer do so. We need a new home for the Windows build slave, so if you have a Windows machine that is permanently on-line and that does not contain mission-critical data, please give me a shout. Thanks! Stéfan ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Windows build-slave needed: please help out!
On Thu, Jun 18, 2009 at 3:58 PM, David Goldsmithd_l_goldsm...@yahoo.com wrote: Hi, Stefan. I was just thinking about the computer I'd designate for this, and remembered that I still have it running XP Pro and don't want to upgrade it to Vista, so there's that to consider. Lots of folks still use XP, so I don't see that as a problem. But it would be nice to have a Vista/Windows7 machine also. Chuck snip ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Windows build-slave needed: please help out!
OK, thanks. I assume, if I'm selected, you'll be making this as plug-and-play as possible? DG --- On Thu, 6/18/09, Charles R Harris charlesr.har...@gmail.com wrote: From: Charles R Harris charlesr.har...@gmail.com Subject: Re: [Numpy-discussion] Windows build-slave needed: please help out! To: Discussion of Numerical Python numpy-discussion@scipy.org Date: Thursday, June 18, 2009, 3:17 PM On Thu, Jun 18, 2009 at 3:58 PM, David Goldsmithd_l_goldsm...@yahoo.com wrote: Hi, Stefan. I was just thinking about the computer I'd designate for this, and remembered that I still have it running XP Pro and don't want to upgrade it to Vista, so there's that to consider. Lots of folks still use XP, so I don't see that as a problem. But it would be nice to have a Vista/Windows7 machine also. Chuck snip ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion