def make_grid(tensor, nrow=<NUM_LIT:8>, padding=<NUM_LIT:2>, pad_value=<NUM_LIT:0>):
if not (isinstance(tensor, np.ndarray) or<EOL>(isinstance(tensor, list) and all(isinstance(t, np.ndarray) for t in tensor))):<EOL><INDENT>raise TypeError('<STR_LIT>'.format(type(tensor)))<EOL><DEDENT>if isinstance(tensor, list):<EOL><INDENT>tensor = np.stack(tensor, <NUM_LIT:0>)<EOL><DEDENT>if tensor.ndim == <NUM_LIT:2>:  <EOL><INDENT>tensor = tensor.reshape((<NUM_LIT:1>, tensor.shape[<NUM_LIT:0>], tensor.shape[<NUM_LIT:1>]))<EOL><DEDENT>if tensor.ndim == <NUM_LIT:3>:<EOL><INDENT>if tensor.shape[<NUM_LIT:0>] == <NUM_LIT:1>:  <EOL><INDENT>tensor = np.concatenate((tensor, tensor, tensor), <NUM_LIT:0>)<EOL><DEDENT>tensor = tensor.reshape((<NUM_LIT:1>, tensor.shape[<NUM_LIT:0>], tensor.shape[<NUM_LIT:1>], tensor.shape[<NUM_LIT:2>]))<EOL><DEDENT>if tensor.ndim == <NUM_LIT:4> and tensor.shape[<NUM_LIT:1>] == <NUM_LIT:1>:  <EOL><INDENT>tensor = np.concatenate((tensor, tensor, tensor), <NUM_LIT:1>)<EOL><DEDENT>if tensor.shape[<NUM_LIT:0>] == <NUM_LIT:1>:<EOL><INDENT>return np.squeeze(tensor)<EOL><DEDENT>nmaps = tensor.shape[<NUM_LIT:0>]<EOL>xmaps = min(nrow, nmaps)<EOL>ymaps = int(math.ceil(float(nmaps) / xmaps))<EOL>height, width = int(tensor.shape[<NUM_LIT:2>] + padding), int(tensor.shape[<NUM_LIT:3>] + padding)<EOL>grid = np.ones((<NUM_LIT:3>, height * ymaps + padding, width * xmaps + padding)) * pad_value<EOL>k = <NUM_LIT:0><EOL>for y in range(ymaps):<EOL><INDENT>for x in range(xmaps):<EOL><INDENT>if k >= nmaps:<EOL><INDENT>break<EOL><DEDENT>grid[:, y * height + padding:(y+<NUM_LIT:1>) * height,x * width + padding:(x+<NUM_LIT:1>) * width] = tensor[k]<EOL>k = k + <NUM_LIT:1><EOL><DEDENT><DEDENT>return grid<EOL>
Make a grid of images, via numpy.

    Args:
        tensor (Tensor or list): 4D mini-batch Tensor of shape (B x C x H x W)
            or a list of images all of the same size.
        nrow (int, optional): Number of images displayed in each row of the grid.
            The Final grid size is (B / nrow, nrow). Default is 8.
        padding (int, optional): amount of padding. Default is 2.
        pad_value (float, optional): Value for the padded pixels.