speedup numpy ufuncs

Pete Shinners pete at visionart.com
Tue Jun 20 19:44:22 EDT 2000


i've been doing some simplish image processing
stuff with numpy and a thought occured to me about
a possible speedup.

if i have 4 or 5 arrays i want to add together,
the fastest way i've found to do this is by
calling the add ufunc many times, specifying an
output argument.
(this gets rid of extra temporary arrays)

array1 = array2 = array3 = array4 = arange(100)
add(array1, array2, array1)
add(array1, array3, array1)
add(array1, array4, array1)

i was wondering if there was a way to add these all
in one pass?
addmany(array1, array2, array3, array4, array1)

would this even make a difference? it just seems
internally numpy could loop over all the input arrays
in one shot, instead of looping for each addition pair.

(this all assumes that
 array1 = array1+array2+array3+array4 is creating
 several many temporaries. after my intial testing
 it seems this is the case)

anyways, it seems this would be a simple addition to
make to numpy (i believe i could crank it out myself)
but i wonder what the insight is on this. would there
really be much benefit by stripping of the excess 
looping?)


along these lines... what is the absolute fastest
quickest way to compute the average of many arrays?
i know (array1+array2+array3)/3 will not be it, but
is there a common "turbo" method for this?



More information about the Python-list mailing list