human
Complete this python program:
def imread(fname):
assistant
#Here is the Python code you requested.

    """Return image file in *fname* as :class:`numpy.array`.
    Return value is a :class:`numpy.array`.  For grayscale images, the
    return array is MxN.  For RGB images, the return value is MxNx3.
    For RGBA images the return value is MxNx4.
    matplotlib can only read PNGs natively, but if `PIL
    <http://www.pythonware.com/products/pil/>`_ is installed, it will
    use it to load the image and return an array (if possible) which
    can be used with :func:`~matplotlib.pyplot.imshow`.
    TODO: support RGB and grayscale return values in _image.readpng
    """
    def pilread():
        'try    to    load    the    image    with    PIL    or    return    None'
        try:
            import Image
        except ImportError:
            return None
        image = Image.open(fname)
        return pil_to_array(image)
    handlers = {'png': _png.read_png}
    (basename, ext) = os.path.splitext(fname)
    ext = ext.lower()[1:]
    if (ext not in handlers.keys()):
        im = pilread()
        if (im is None):
            raise ValueError(('Only    know    how    to    handle    extensions:    %s;    with    PIL    installed    matplotlib    can    handle    more    images' % handlers.keys()))
        return im
    handler = handlers[ext]
    return handler(fname)