[Numpy-discussion] nested loops too slow

Florian Mueller icephase26 at gmail.com
Thu Aug 9 04:01:31 EDT 2012

Hi Nico,

Using for-loops for numerical calculations is often problematic for
numerical calculations. I don't understand the fancy stuff with the
indexing of the arrays. Can you provide a working example script
and/or a brief description of the calculation you are performing
(including equations)? How does the array look like?

Best regards,

On Wed, Aug 8, 2012 at 3:47 PM, nicolas aunai <nicolas.aunai at gmail.com> wrote:
> Hi,
> I'm trying to write a code for doing a 2D integral. It works well when
> I'm doing it with normal "for" loops, but requires two nested loops,
> and is much too slow for my application. I would like to know if it is
> possible to do it faster, for example with fancy indexing and the use
> of numpy.cumsum(). I couln't find a solution, do you have an idea ?
> The code is the following :
> http://bpaste.net/show/cAkMBd3sUmhDXq0sIpZ5/
> 'flux2' is the result of the calculation with 'for' loops
> implementation, and 'flux' is supposed to be the same result without
> the loop. If I managed to do it for the single loops (line 23 is
> identical to lines 20-21, and line 30 is identical to line 27,28) and
> don't know how to do for the nested loops lines 33-35 (line 40 does
> not give the same result).
> Any idea ?
> Thanks much
> Nico
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

More information about the NumPy-Discussion mailing list