I frequently find I have my 1d function that performs some reduction that I'd like to apply-along some axis of an n-d array. As a trivial example, def sum(u): return np.sum (u) In this case the function is probably C/C++ code, but that is irrelevant (I think). Is there a reasonably efficient way to do this within numpy?
On 22 Mar 2013 14:09, "Neal Becker"
I frequently find I have my 1d function that performs some reduction that
I'd
like to apply-along some axis of an n-d array.
As a trivial example,
def sum(u): return np.sum (u)
In this case the function is probably C/C++ code, but that is irrelevant (I think).
Is there a reasonably efficient way to do this within numpy?
The core infrastructure for this sort of thing is there - search on "generalized ufuncs". There's no python-level api as far as I know, though, yet. You could write a reasonable facsimile of np.vectorize for such functions using nditer. -n
This is the closer I got to do what you say
http://numpy-discussion.10968.n7.nabble.com/Reductions-with-nditer-working-o...
Converts a 3D to 2D, but only works in the last axis. Any improvement would
be welcomed.ç
2013/3/22 Neal Becker
I frequently find I have my 1d function that performs some reduction that I'd like to apply-along some axis of an n-d array.
As a trivial example,
def sum(u): return np.sum (u)
In this case the function is probably C/C++ code, but that is irrelevant (I think).
Is there a reasonably efficient way to do this within numpy?
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
participants (3)
-
Nathaniel Smith
-
Neal Becker
-
Sergio Pascual