Re: question on list comprehensions
From: Carlos Ribeiro (carribeiro_at_gmail.com)
Date: 10/14/04
- Next message: Darren Dale: "Re: question on list comprehensions"
- Previous message: valued customer: "Re: Completely INNOCENT Indentation question"
- In reply to: Darren Dale: "Re: question on list comprehensions"
- Next in thread: Darren Dale: "Re: question on list comprehensions"
- Reply: Darren Dale: "Re: question on list comprehensions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Darren Dale: "Re: question on list comprehensions"
- Previous message: valued customer: "Re: Completely INNOCENT Indentation question"
- In reply to: Darren Dale: "Re: question on list comprehensions"
- Next in thread: Darren Dale: "Re: question on list comprehensions"
- Reply: Darren Dale: "Re: question on list comprehensions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|