human
I wrote the below code

    as_scalar = numpy.isscalar(index)
    input = numpy.asarray(input)
    if pass_positions:
        positions = numpy.arange(input.size).reshape(input.shape)
    if (labels is None):
        if (index is not None):
            raise ValueError('index    without    defined    labels')
        if (not pass_positions):
            return func(input.ravel())
        else:
            return func(input.ravel(), positions.ravel())
    try:
        (input, labels) = numpy.broadcast_arrays(input, labels)
    except ValueError:
        raise ValueError('input    and    labels    must    have    the    same    shape    (excepting    dimensions    with    width    1)')
    if (index is None):
        if (not pass_positions):
            return func(input[(labels > 0)])
        else:
            return func(input[(labels > 0)], positions[(labels > 0)])
    index = numpy.atleast_1d(index)
    if np.any((index.astype(labels.dtype).astype(index.dtype) != index)):
        raise ValueError(("Cannot    convert    index    values    from    <%s>    to    <%s>    (labels'    type)    without    loss    of    precision" % (index.dtype, labels.dtype)))
    index = index.astype(labels.dtype)
    lo = index.min()
    hi = index.max()
    mask = ((labels >= lo) & (labels <= hi))
    labels = labels[mask]
    input = input[mask]
    if pass_positions:
        positions = positions[mask]
    label_order = labels.argsort()
    labels = labels[label_order]
    input = input[label_order]
    if pass_positions:
        positions = positions[label_order]
    index_order = index.argsort()
    sorted_index = index[index_order]
    def do_map(inputs, output):
        'labels    must    be    sorted'
        nidx = sorted_index.size
        lo = numpy.searchsorted(labels, sorted_index, side='left')
        hi = numpy.searchsorted(labels, sorted_index, side='right')
        for (i, l, h) in zip(range(nidx), lo, hi):
            if (l == h):
                continue
            output[i] = func(*[inp[l:h] for inp in inputs])
    temp =...

What's a good function header?
 ... Here's a good function header?
assistant
#Here's a good function header.

def labeled_comprehension(input, labels, index, func, out_dtype, default, pass_positions=False):