[SciPy-user] Accelerating the calculation of a function

Gael Varoquaux gael.varoquaux at normalesup.org
Mon Aug 7 01:27:49 CDT 2006

On Mon, Aug 07, 2006 at 05:26:04AM +0200, Steve Schmerler wrote:
>( things such as : sum( [F(k) for k in lasers]) ).

> You're most probably doing it already (I just wondered about the list 
> comprehension): Can you do numpy.sum(F(lasers)) in your function (that 
> is, is 'lasers' a simple array)?

    I have been turning this around in my head wondering whether to do
it or not. The problem is that F is already a 2D array, and that I would
have to add an extra dimension to it to be able to sum it (and it has
matrix and array products in its definition, so writing it starts
getting really ugly, and my current problem is rather finding the errors
in the different formulas). len(laser) = 6, so this shouldn't be to bad.
Actually the best way to implement that sum would a macro (in another
language then python).

    Hint for the numpy developpers: maybe a nice function to make code
readable and fast would be to have a function that does this with arrays
without having to write F compatible with arrays (ie no "frames are not
aligned" problems). Something like:

sumover(F,lasers,1) where F would be a callable, lasers an array, and
the last argument (optional) the direction of the array in which the sum
should happen.

    I do not know if this is possible but this would be useful.


More information about the SciPy-user mailing list