

def tile_raster_images(X, img_shape, tile_shape, tile_spacing=(0, 0), scale=True, output_pixel_vals=True, colorImg=False):
    '\n    Transform an array with one flattened image per row, into an array in\n    which images are reshaped and layed out like tiles on a floor.\n\n    This function is useful for visualizing datasets whose rows are images,\n    and also columns of matrices for transforming those rows\n    (such as the first layer of a neural net).\n\n    :type X: a 2-D ndarray or a tuple of 4 channels, elements of which can\n    be 2-D ndarrays or None;\n    :param X: a 2-D array in which every row is a flattened image.\n\n    :type img_shape: tuple; (height, width)\n    :param img_shape: the original shape of each image\n\n    :type tile_shape: tuple; (rows, cols)\n    :param tile_shape: the number of images to tile (rows, cols)\n\n    :param output_pixel_vals: if output should be pixel values (i.e. int8\n    values) or floats\n\n    :param scale_rows_to_unit_interval: if the values need to be scaled before\n    being plotted to [0,1] or not\n\n\n    :returns: array suitable for viewing as an image.\n    (See:`PIL.Image.fromarray`.)\n    :rtype: a 2-d array with same dtype as X.\n\n    '
    X = (X * 1.0)
    if colorImg:
        channelSize = (X.shape[1] / 3)
        X = (X[:, 0:channelSize], X[:, channelSize:(2 * channelSize)], X[:, (2 * channelSize):(3 * channelSize)], None)
    assert (len(img_shape) == 2)
    assert (len(tile_shape) == 2)
    assert (len(tile_spacing) == 2)
    out_shape = [(((ishp + tsp) * tshp) - tsp) for (ishp, tshp, tsp) in zip(img_shape, tile_shape, tile_spacing)]
    if isinstance(X, tuple):
        assert (len(X) == 4)
        if output_pixel_vals:
            out_array = np.zeros((out_shape[0], out_shape[1], 4), dtype='uint8')
        else:
            out_array = np.zeros((out_shape[0], out_shape[1], 4), dtype=X.dtype)
        if output_pixel_vals:
            channel_defaults = [0, 0, 0, 255]
        else:
            channel_defaults = [0.0, 0.0, 0.0, 1.0]
        for i in xrange(4):
            if (X[i] is None):
                out_array[:, :, i] = (np.zeros(out_shape, dtype=('uint8' if output_pixel_vals else out_array.dtype)) + channel_defaults[i])
            else:
                xi = X[i]
                if scale:
                    xi = ((X[i] - X[i].min()) / (X[i].max() - X[i].min()))
                out_array[:, :, i] = tile_raster_images(xi, img_shape, tile_shape, tile_spacing, False, output_pixel_vals)
        return out_array
    else:
        (H, W) = img_shape
        (Hs, Ws) = tile_spacing
        out_array = np.zeros(out_shape, dtype=('uint8' if output_pixel_vals else X.dtype))
        for tile_row in xrange(tile_shape[0]):
            for tile_col in xrange(tile_shape[1]):
                if (((tile_row * tile_shape[1]) + tile_col) < X.shape[0]):
                    if scale:
                        tmp = X[((tile_row * tile_shape[1]) + tile_col)].reshape(img_shape)
                        this_img = scale_to_unit_interval(tmp)
                    else:
                        this_img = X[((tile_row * tile_shape[1]) + tile_col)].reshape(img_shape)
                    out_array[(tile_row * (H + Hs)):((tile_row * (H + Hs)) + H), (tile_col * (W + Ws)):((tile_col * (W + Ws)) + W)] = (this_img * (255 if output_pixel_vals else 1))
        return out_array

dataset/ETHPy150Open dpkingma/nips14-ssl/anglepy/paramgraphics.py tile_raster_images/original