[Numpy-discussion] howto reduce along arbitrary axis
Neal Becker
ndbecker2 at gmail.com
Tue Mar 26 09:07:07 EDT 2013
In the following code, the function maxstar is applied along the
last axis. Can anyone suggest how to modify this to apply reduction along
a user-specified axis?
def maxstar2 (a, b):
return max (a, b) + log1p (exp (-abs (a - b)))
def maxstar (u):
s = u.shape[-1]
if s == 1:
return u[...,0]
elif s == 2:
return maxstar2 (u[...,0], u[...,1])
else:
return maxstar2 (
maxstar (u[...,:s/2]),
maxstar (u[...,s/2:]))
More information about the NumPy-Discussion
mailing list