<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><br>Thank you very much Robert !<br>For really big matrices, "<span style="font-weight: bold;">where</span>" is 4 times faster ! For small matrices, it's slower than my old solution, but it really doesn't matter, it's fast enough. :)<br>I will think about "<span style="font-weight: bold;">put</span>" too. I used it before, but i must adapt all functions to obtain the necessary indexes.<br><br>Have a nice day !<br><br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;">From: Robert <kxroberto@googlemail.com><br>Subject: Re: [Numpy-discussion] Advanced indexing advice?<br>To: numpy-discussion@scipy.org<br>Date: Friday, June 19, 2009, 6:49 AM<br><br><div class="plainMail">well its not really slow.<br>yet with np.where it seems to be 2x faster for large arrays :<br><br>a[1:4,1:4] =
 np.where(mask,b,a[1:4,1:4])<br><br>otherwise consider Cython: <br><a href="http://docs.cython.org/docs/numpy_tutorial.html#tuning-indexing-further" target="_blank">http://docs.cython.org/docs/numpy_tutorial.html#tuning-indexing-further</a><br><br><br>Robert<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>>     </mc/compose?to=<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,<br>>     but use offset!<br><br></div></blockquote></td></tr></table><br>