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
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to