<div dir="ltr">Dear Peter<div><br></div><div style>thanks . But thats what I was trying to say </div><div style><br></div><div style>just taking them to zero by f[:,:,:] = 0.0 or using np.zeros is surely going to give me a time gain...</div>
<div style>but my example of using the itertools.product() and doing f[x] =0.0 is just to compare the looping timing with the traditional nested loops and not to distract us to the operation done inside the loop.</div><div style>
<br></div><div style>right?</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Aug 6, 2014 at 6:09 PM, Peter Otten <span dir="ltr"><<a href="mailto:__peter__@web.de" target="_blank">__peter__@web.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">Gayathri J wrote:<br>
<br>
> Dear Peter<br>
><br>
> Yes the f[t] or f[:,:,:] might give a marginal increase,<br>
<br>
</div>The speedup compared itertools.product() is significant:<br>
<br>
$ python -m timeit -s 'from itertools import product; from numpy.random<br>
import rand; N = 100; a = rand(N, N, N); r = range(N)' 'for x in product(r,<br>
repeat=3): a[x] = 0.0'<br>
10 loops, best of 3: 290 msec per loop<br>
<br>
$ python -m timeit -s 'from itertools import product; from numpy.random<br>
import rand; N = 100; a = rand(N, N, N); r = range(N)' 'a[:,:,:] = 0.0'<br>
100 loops, best of 3: 3.58 msec per loop<br>
<br>
But normally you'd just make a new array with numpy.zeros().<br>
<div class=""><br>
> but then i need<br>
> to do further operations using the indices, in which case this wouldnt<br>
> help<br>
<br>
</div>Which is expected and also the crux of such micro-benchmarks. They distract<br>
from big picture.<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
<a href="https://mail.python.org/mailman/listinfo/python-list" target="_blank">https://mail.python.org/mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br></div>