What's the quickest way (without going into parallel processing) to find a sum of results of function calls in Python?
Imagine xlist
is a list of values, the purpose is to transform each of them with f(x)
and sum up. For now (keeping in mind "flat is always better") I have:
sum([f(x) for x in xlist])
This works fine, but my xlist
is pretty large (~20000 float values) and this sum is called a few million times during the execution of my program, consuming most of the time resources. Is there a way to implement it in a more efficient fashion?
I don't mind adding C++ inclusions or whatever other methods you could think of, but would not want to change the structure of the whole program for the sake of it...