2006/10/19, Robert Kern <rob...@gm...>:
> def nonreducing_reducer(reducing_func, arr, axis):
> reduced = reducing_func(arr, axis=axis)
> shape = list(reduced.shape)
> axis = axis % len(arr.shape)
> shape.insert(axis, 1)
> reduced.shape = tuple(shape)
> return reduced
Cute !
Here is another one:
1dfunc = lambda x: atleast_1d(reducing_function(x))
apply_along_axis(1dfunc, axis, arr)
Is it something people often need ? Would it be worth, (for numpy 1.1 ?), to
consider complex axis arguments as a wish to preserve the rank of the array?
>>> a.shape
(n,m,o,p)
>>> a.sum(axis=1j)
(n,1,o,p)
>>> a.sum(axis=1)
(n,o,p)
Thanks,
David
|