Dear Peter thanks . But thats what I was trying to say
just taking them to zero by f[:,:,:] = 0.0 or using np.zeros is surely going to give me a time gain... 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. right? On Wed, Aug 6, 2014 at 6:09 PM, Peter Otten <__pete...@web.de> wrote: > Gayathri J wrote: > > > Dear Peter > > > > Yes the f[t] or f[:,:,:] might give a marginal increase, > > The speedup compared itertools.product() is significant: > > $ python -m timeit -s 'from itertools import product; from numpy.random > import rand; N = 100; a = rand(N, N, N); r = range(N)' 'for x in product(r, > repeat=3): a[x] = 0.0' > 10 loops, best of 3: 290 msec per loop > > $ python -m timeit -s 'from itertools import product; from numpy.random > import rand; N = 100; a = rand(N, N, N); r = range(N)' 'a[:,:,:] = 0.0' > 100 loops, best of 3: 3.58 msec per loop > > But normally you'd just make a new array with numpy.zeros(). > > > but then i need > > to do further operations using the indices, in which case this wouldnt > > help > > Which is expected and also the crux of such micro-benchmarks. They distract > from big picture. > > -- > https://mail.python.org/mailman/listinfo/python-list >
-- https://mail.python.org/mailman/listinfo/python-list