<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><br>Thank you so much for your prompt answer, Stéfan.<br>It's a very very interesting method. I will keep it for future. :)<br><br>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.<br><br>Thank you again. I will play with your method a little more.<br><br>--- On <b>Thu, 6/18/09, Stéfan van der Walt <i><stefan@sun.ac.za></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;">From: Stéfan van der Walt <stefan@sun.ac.za><br>Subject: Re: [Numpy-discussion] Advanced indexing advice?<br>To: "Discussion of Numerical Python" <numpy-discussion@scipy.org><br>Date: Thursday, June 18, 2009, 2:16 AM<br><br><div class="plainMail">Hi Cristi<br><br>2009/6/18 Cristi Constantin
<<a ymailto="mailto:darkgl0w@yahoo.com" href="/mc/compose?to=darkgl0w@yahoo.com">darkgl0w@yahoo.com</a>>:<br>> I have a question about advanced indexing.<br>><br>> I have 2 matrices :<br>><br>>>>><br>> a=array([[ 0, 1, 2, 3, 4, 5],<br>> [ 6, 7, 8, 9, 10, 11],<br>> [12, 13, 14, 15, 16, 17],<br>> [18, 19, 20, 21, 22, 23]])<br>><br>> b=array([[1, 0, 1],<br>> [0, 2, 0],<br>> [0, 0, 3]])<br>>>>><br>><br>> I want to put all NON-zero elements from array B into array A, but use<br>> offset!<br><br>Here's a solution using views:<br><br>offset = np.array([1,1])<br>slices = [slice(*x) for x in
zip(offset, offset + b.shape)]<br>c = a[slices]<br>mask = (b != 0)<br>c[mask] = b[mask]<br><br>Regards<br>Stéfan<br><br></div></blockquote></td></tr></table><br>