[SciPy-user] apply_along_axis but with multiple arguments

R. Padraic Springuel R.Springuel@umit.maine....
Fri Jan 18 13:23:11 CST 2008


I've written my own function that works on an array and am attempting to 
add axis control to that function so that it works similar to mean, sum, 
etc. which already exist in numpy.  Said function, however, has the 
option of weighting each point differently when doing its calculations 
according to an optional weights argument (similar to average).  Thus, 
in adding axis control to the function, I have to pull sub-arrays from 
two arrays simultaneously (the data and weights), and do so in such a 
way that they correspond to each other appropriately.  I've thought 
about using apply_along_axis to do this, but it seems that the function 
doesn't allow the simultaneous variation of two arrays, only the 
variation of one.  Can anyone shed some light on how I might do this?

Since I'm not sure the above is totally clear, let me try putting it 
this way too:
Let's assume for the moment that the average function in numpy didn't 
have axis control built into it.  If I wanted to take the weighted 
average of an array along a certain axis could I use apply_along_axis in 
such a way that both a (the data) and weights are varied simultaneously 
along that axis?  I.e. I'm looking for a way to use apply_along_axis to 
duplicate average(a,axis,weights) using average(a,weights) in the same 
way that
apply_along_axis(average,axis,a) duplicates average(a,axis).  Would 
apply_over_axes or vectorize be more appropriate, and if so how?
-- 

R. Padraic Springuel
Teaching Assistant
Department of Physics and Astronomy
University of Maine
Bennett 309
Office Hours: By appointment only


More information about the SciPy-user mailing list