def visualize_grid(Xs, ubound=255.0, padding=1, grid_size=None):
    (N, H, W, C) = Xs.shape

    if grid_size is None:
        grid_size_y = grid_size_x = int(ceil(sqrt(N)))
    elif type(grid_size) == tuple:
        grid_size_x = grid_size[0]
        grid_size_y = grid_size[1]
    else:
        grid_size_y = grid_size_x = grid_size

    grid_height = H * grid_size_y + padding * (grid_size_y - 1)
    grid_width = W * grid_size_x + padding * (grid_size_x - 1)
    grid = np.zeros((grid_height, grid_width, C))
    next_idx = 0
    y0, y1 = 0, H
    for y in xrange(grid_size_y):
        x0, x1 = 0, W
        for x in xrange(grid_size_x):
            if next_idx < N:
                img = Xs[next_idx]
                low, high = np.min(img), np.max(img)
                grid[y0:y1, x0:x1] = ubound * (img - low) / (high - low)
                # grid[y0:y1, x0:x1] = Xs[next_idx]
                next_idx += 1
            x0 += W + padding
            x1 += W + padding
        y0 += H + padding
        y1 += H + padding
    # grid_max = np.max(grid)
    # grid_min = np.min(grid)
    # grid = ubound * (grid - grid_min) / (grid_max - grid_min)
    return grid
Reshape a 4D tensor of image data to a grid for easy visualization.
dataset/ETHPy150Open dnlcrl/PyFunt/pyfunt/utils/vis_utils.py/visualize_grid