human
Write me a Python program to compute (sum - centre)^2 of input by label given the following:
Complete the below
def _stats(input, labels=None, index=None, centered=False):

    ''''Count, sum, and optionally compute (sum - centre)^2 of input by label
    Parameters
    input : array_like, n-dimensional
    The input data to be analyzed.
    labels : array_like (n-dimensional), optional
    The labels of the data in `input`.  This array must be broadcast
    compatible with `input`.
typically it is the same shape as `input`.
    If `labels` is None, all nonzero values in `input` are treated as
    the single labeled group.
    index : label or sequence of labels, optional
    These are the labels of the groups for which the stats are computed.
    If `index` is None, the stats are computed for the single group where
    `labels` is greater than 0.
    centered : bool, optional
    If True, the centered sum of squares for each labeled group is
    also returned.  Default is False.
    Returns
    counts : int or ndarray of ints
    The number of elements in each labeled group.
    sums : scalar or ndarray of scalars
    The sums of the values in each labeled group.
    sums_c : scalar or ndarray of scalars, optional
    The sums of mean-centered squares of the values in each labeled group.
    This is only returned if `centered` is True.'
    '''
assistant
#Here is Python program to compute (sum - centre)^2 of input by label
.
    def single_group(vals):
        if centered:
            vals_c = (vals - vals.mean())
            return (vals.size, vals.sum(), (vals_c * vals_c.conjugate()).sum())
        else:
            return (vals.size, vals.sum())
    if (labels is None):
        return single_group(input)
    (input, labels) = numpy.broadcast_arrays(input, labels)
    if (index is None):
        return single_group(input[(labels > 0)])
    if numpy.isscalar(index):
        return single_group(input[(labels == index)])
    def _sum_centered(labels):
        means = (sums / counts)
        centered_input = (input - means[labels])
        bc = numpy.bincount(labels.ravel(), weights=(centered_input * centered_input.conjugate()).ravel())
        return bc
    if ((not _safely_castable_to_int(labels.dtype)) or (labels.min() < 0) or (labels.max() > labels.size)):
        (unique_labels, new_labels) = numpy.unique(labels, return_inverse=True)
        counts = numpy.bincount(new_labels)
        sums = numpy.bincount(new_labels, weights=input.ravel())
        if centered:
            sums_c = _sum_centered(new_labels.reshape(labels.shape))
        idxs = numpy.searchsorted(unique_labels, index)
        idxs[(idxs >= unique_labels.size)] = 0
        found = (unique_labels[idxs] == index)
    else:
        counts = numpy.bincount(labels.ravel())
        sums = numpy.bincount(labels.ravel(), weights=input.ravel())
        if centered:
            sums_c = _sum_centered(labels)
        idxs = numpy.asanyarray(index, numpy.int).copy()
        found = ((idxs >= 0) & (idxs < counts.size))
        idxs[(~ found)] = 0
    counts = counts[idxs]
    counts[(~ found)] = 0
    sums = sums[idxs]
    sums[(~ found)] = 0
    if (not centered):
        return (counts, sums)
    else:
        sums_c = sums_c[idxs]
        sums_c[(~ found)] = 0
        return (counts, sums, sums_c)