[Scipy-tickets] [SciPy] #1565: bug in ndimage.variance

SciPy Trac scipy-tickets@scipy....
Sat Nov 26 23:22:12 CST 2011


#1565: bug in ndimage.variance
-----------------------------------+----------------------------------------
 Reporter:  kazboris021            |       Owner:  somebody   
     Type:  defect                 |      Status:  new        
 Priority:  normal                 |   Milestone:  Unscheduled
Component:  scipy.ndimage          |     Version:  0.9.0      
 Keywords:  scipy, numpy, ndimage  |  
-----------------------------------+----------------------------------------

Comment(by warren.weckesser):

 Even the example in the docstring of ndimage.variance is broken:
 {{{
 In [28]: import scipy.ndimage as ndi

 In [29]: a = array([[1,2,0,0], [5,3,0,4], [0,0,0,7], [9,3,0,0]])

 In [30]: a
 Out[30]:
 array([[1, 2, 0, 0],
        [5, 3, 0, 4],
        [0, 0, 0, 7],
        [9, 3, 0, 0]])

 In [31]: lbl, nlbl = ndi.label(a)

 In [32]: lbl, nlbl
 Out[32]:
 (array([[1, 1, 0, 0],
        [1, 1, 0, 2],
        [0, 0, 0, 2],
        [3, 3, 0, 0]]),
  3)

 In [33]: ndi.variance(a, lbl, index=arange(1,nlbl+1))
 ---------------------------------------------------------------------------
 ValueError                                Traceback (most recent call
 last)
 /Users/warren/<ipython-input-33-7a79c06fbc7d> in <module>()
 ----> 1 ndi.variance(a, lbl, index=arange(1,nlbl+1))

 /Users/warren/local_scipy/lib/python2.7/site-
 packages/scipy/ndimage/measurements.pyc in variance(input, labels, index)
     587     """
     588
 --> 589     count, sum, sum_c_sq = _stats(input, labels, index,
 centered=True)
     590
     591     return sum_c_sq / np.asanyarray(count).astype(float)

 /Users/warren/local_scipy/lib/python2.7/site-
 packages/scipy/ndimage/measurements.pyc in _stats(input, labels, index,
 centered)
     430         sums = numpy.bincount(labels.ravel(),
 weights=input.ravel())
     431         if centered:
 --> 432             sums_c = _sum_centered(labels.ravel())
     433         # make sure all index values are valid

     434         idxs = numpy.asanyarray(index, numpy.int).copy()

 /Users/warren/local_scipy/lib/python2.7/site-
 packages/scipy/ndimage/measurements.pyc in _sum_centered(labels)
     404     def _sum_centered(labels):
     405         means = sums / counts
 --> 406         centered_input = input - means[labels]
     407         bc = numpy.bincount(labels,
     408                               weights=(centered_input * \

 ValueError: operands could not be broadcast together with shapes (4,4)
 (16)
 }}}
 (numpy 1.6.1, scipy 0.11.0.dev-f47d2f1)

-- 
Ticket URL: <http://projects.scipy.org/scipy/ticket/1565#comment:2>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list