[Numpy-discussion] bug in numpy.apply_along_axis: numpy.__version__ '1.0.3.1'

Sean Ross-Ross srossross@gmail....
Sat Nov 17 02:37:25 CST 2007


Hi, I think I have found a bug in the function "apply_along_axis".

recall that the function definition if apply_along_axis(func1d, axis,  
arr, *args)

This bug occurs if func1d returns a python object without a __len__  
attribute and is not a scalar, determined by  
numpy.core.numeric.isscalar.

eg. a self contained example of the bug is:

 >>> from numpy import array, apply_along_axis
 >>>
 >>> # works
 >>> arr = array( [1,1] )
 >>> apply_along_axis( lambda arr:arr[0], 0, arr )
 >>>
 >>> # however this raises a type error
 >>> class Foo(object): pass
 >>>
 >>> arr = array( [ Foo(), Foo() ] )
 >>> apply_along_axis( lambda arr:arr[0], 0, arr )
------------------------------------------------------------------------ 
---
exceptions.TypeError                                 Traceback (most  
recent call last)

/sw/lib/python2.4/site-packages/numpy/lib/shape_base.py in  
apply_along_axis(func1d, axis, arr, *args)
        52         holdshape = outshape
        53         outshape = list(arr.shape)
---> 54         outshape[axis] = len(res)
        55         outarr = zeros(outshape,asarray(res).dtype)
        56         outarr[tuple(i.tolist())] = res

TypeError: len() of unsized object
 >>>

Thanks

~Sean
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20071117/65629a92/attachment.html 


More information about the Numpy-discussion mailing list