[SciPy-user] easy to fix bug in ndimage.center_of_mass

Sebastian Haase haase@msg.ucsf....
Thu Jun 5 06:23:43 CDT 2008


Hi,
I found this code in measurements.py
def center_of_mass(input, labels = None, index = None):
    """Calculate the center of mass of of the array.

    The index parameter is a single label number or a sequence of
    label numbers of the objects to be measured. If index is None, all
    values are used where labels is larger than zero.
    """
    input = numpy.asarray(input)
    if numpy.iscomplexobj(input):
        raise TypeError, 'Complex type not supported'
    if labels != None:
        labels = numpy.asarray(labels)
        labels = _broadcast(labels, input.shape)

        if labels.shape != input.shape:
            raise RuntimeError, 'input and labels shape are not equal'
    return _nd_image.center_of_mass(input, labels, index)


but the if part:
if labels.shape != input.shape:

is probably indented one level too much !?

Regards,
Sebastian


More information about the SciPy-user mailing list