human
I wrote the below code

    def toarray(im, dtype=np.uint8):
        'Return    a    1D    array    of    dtype.'
        if hasattr(im, 'tobytes'):
            x_str = im.tobytes('raw', im.mode)
        else:
            x_str = im.tostring('raw', im.mode)
        x = np.fromstring(x_str, dtype)
        return x
    if (pilImage.mode in ('RGBA', 'RGBX')):
        im = pilImage
    elif (pilImage.mode == 'L'):
        im = pilImage
        x = toarray(im)
        x.shape = (im.size[1], im.size[0])
        return x
    elif (pilImage.mode == 'RGB'):
        im = pilImage
        x = toarray(im)
        x.shape = (im.size[1], im.size[0], 3)
        return x
    elif pilImage.mode.startswith('I;16'):
        im = pilImage
        if im.mode.endswith('B'):
            x = toarray(im, '>u2')
        else:
            x = toarray(im, '<u2')
        x.shape = (im.size[1], im.size[0])
        return x.astype('=u2')
    else:
        try:
            im = pilImage.convert('RGBA')
        except ValueError:
            raise RuntimeError('Unknown    image    mode')
    x = toarray(im)
    x.shape = (im.size[1], im.size[0], 4)
    return x

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

def pil_to_array(pilImage):