Re: question on list comprehensions

From: Carlos Ribeiro (carribeiro_at_gmail.com)
Date: 10/14/04


Date: Thu, 14 Oct 2004 13:59:41 -0300
To: dd55@cornell.edu

On Thu, 14 Oct 2004 11:16:12 -0400, Darren Dale <dd55@cornell.edu> wrote:
> I am simulating diffraction from an array of particles. I have to calculate
> a complex array for each particle, add up all these arrays, and square the
> magnitude of the result. If I do a for loop, it takes about 6-8 seconds for
> a 2000 element array added up over 250 particles. In reality, I will have
> 2500 particles, or even 2500x2500 particles.

Can't you just sum them inplace as you calculate every new array, for
each particle? Something like this (pseudo code):

result = make_empty_array()
for particle in particles:
    result += make_complex_array(particle)
return square(result)

It does not grow the result array indefinitely.... so it solves your
problem, if that's what you need/want to avoid.

-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: carribeiro@gmail.com
mail: carribeiro@yahoo.com


Relevant Pages

  • Re: Representing structures for simulations
    ... multidimensional array. ... cartesian grid; the grid can be distorted in various ways (e.g., ... Because the adjacency information is precomputed ... One simple method is storing, with each particle, a list of all of the ...
    (comp.lang.fortran)
  • Re: Optimization in gfortran
    ... optimisation leading to an infinite loop) but this could be a bug in your code too. ... is periodic) with a costant mesure, I wait they reach the asyntotic mesure and the I pass throw the integrator all the particle at the same time: for t=1 I integrate all the particle to t=1.01 and so on. ... In the secondo I put a single particle, store the relevant quantity in an array, every x time I do a cut and I recall the particle as the second particle and so on. ...
    (comp.lang.fortran)
  • Re: question on list comprehensions
    ... >> I am simulating diffraction from an array of particles. ... > each particle? ... the overhead in the for loop can be ... The list comprehension wants to create a new list instead. ...
    (comp.lang.python)
  • Re: foreach vs. for
    ... You can read my full examination of these methods on my blog. ... The semantics of foreach (storing a local ... version of the array and a local copy of the array element) are required, ... I also noted that the conv instruction was apparent in the for> version also. ...
    (microsoft.public.dotnet.framework.performance)
  • Re: foreach vs. for
    ... You can read my full examination of these methods on my blog. ... The semantics of foreach (storing a local ... version of the array and a local copy of the array element) are required, ... I also noted that the conv instruction was apparent in the for> version also. ...
    (microsoft.public.dotnet.general)