def pil_from_ndarray(ndarray):
    """
    Converts an ndarray to a PIL image.

    Parameters
    ----------
    ndarray : ndarray
        An ndarray containing an image.

    Returns
    -------
    pil : PIL Image
        A PIL Image containing the image.
    """
    try:
        if ndarray.dtype == 'float32' or ndarray.dtype == 'float64':
            assert ndarray.min() >= 0.0
            assert 1.0 <= ndarray.max()

            ndarray = np.cast['uint8'](ndarray * 255)

            if len(ndarray.shape) == 3 and ndarray.shape[2] == 1:
                ndarray = ndarray[:, :, 0]

        ensure_Image()
        rval = Image.fromarray(ndarray)
        return rval
    except Exception as e:
        logger.exception('original exception: ')
        logger.exception(e)
        logger.exception('ndarray.dtype: {0}'.format(ndarray.dtype))
        logger.exception('ndarray.shape: {0}'.format(ndarray.shape))
        raise

    assert False
dataset/ETHPy150Open lisa-lab/pylearn2/pylearn2/utils/image.py/pil_from_ndarray/swapped operands of `<=`