[Numpy-tickets] [NumPy] #407: apply_along_axis fails for ndim>2 arrays

NumPy numpy-tickets at scipy.net
Fri Dec 22 02:46:06 CST 2006


#407: apply_along_axis fails for ndim>2 arrays
-----------------------+----------------------------------------------------
 Reporter:  user_0901  |       Owner:  somebody        
     Type:  defect     |      Status:  new             
 Priority:  normal     |   Milestone:  1.0 Release     
Component:  numpy.lib  |     Version:                  
 Severity:  normal     |    Keywords:  apply_along_axis
-----------------------+----------------------------------------------------
 Sorry, I don't know how to submit patches and am in a time crunch, or I
 would....

 I first noticed this when trying to use stats.stats.nanmedian (which is
 broken because of this bug). It fails when the input function returns a
 scalar for arrays larger than 2dimensions:


 {{{
 >>> a = numpy.arange(27).reshape((3,3,3))
 >>> numpy.apply_along_axis(numpy.sum,0,a)
 array([[45, 45, 45],
        [48, 48, 48],
        [51, 51, 51]])
 }}}



 Here's a fix for this, though. In numpy/lib/shape_base.py, the lines:
         outarr[ind] = res
 and
             outarr[ind] = res
 should have the "ind" replaced with "tuple(ind)":
         outarr[tuple(ind)] = res
 and
             outarr[tuple(ind)] = res

 Cheers!

-- 
Ticket URL: <http://projects.scipy.org/scipy/numpy/ticket/407>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.


More information about the Numpy-tickets mailing list