
Hi, I'm confused by the output of apply_along_axis() in the following very simple example: In [93]: a = arange(12.).reshape(2,2,3) In [95]: a Out[95]: array([[[ 0., 1., 2.], [ 3., 4., 5.]], [[ 6., 7., 8.], [ 9., 10., 11.]]]) In [96]: def myfunc(b): ....: print "slice:", b, " middle value:", b[1] ....: return b[1] ....: In [97]: apply_along_axis(myfunc,2,a) slice: [ 0. 1. 2.] middle value: 1.0 slice: [ 3. 4. 5.] middle value: 4.0 slice: [ 6. 7. 8.] middle value: 7.0 slice: [ 9. 10. 11.] middle value: 10.0 Out[97]: array([[ 7., 7.], [ 10., 10.]]) I expected as output array([[ 1., 4.], [ 7., 10.]]) Why is this not the case? How exactly does apply_along_axis() use the output of myfunc() to produce its result? Cheers, J. P.S. I'm working with Python 2.5 & Numpy 1.0 Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

On Wednesday 07 February 2007 15:22, Stefan van der Walt wrote:
On Wed, Feb 07, 2007 at 03:11:53PM +0100, Joris De Ridder wrote:
I expected as output array([[ 1., 4.], [ 7., 10.]])
That is the answer I get with numpy 1.0.2.dev3537 under Python 2.4.
Python 2.5 + numpy 1.0.2.dev3540 also solved the problem for me. Thanks, Joris Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
participants (2)
-
Joris De Ridder
-
Stefan van der Walt