def _prepare_image(img, nrow=<NUM_LIT:8>, padding=<NUM_LIT:2>, square_image=False):
if isinstance(img, np.ndarray):<EOL><INDENT>img = nd.array(img, dtype=img.dtype, ctx=current_context())<EOL><DEDENT>if not isinstance(img, NDArray):<EOL><INDENT>raise TypeError('<STR_LIT>'<EOL>'<STR_LIT>'.format(str(type(img))))<EOL><DEDENT>assert img.ndim == <NUM_LIT:2> or img.ndim == <NUM_LIT:3> or img.ndim == <NUM_LIT:4><EOL>if img.dtype == np.uint8:<EOL><INDENT>return make_image_grid(<EOL>img, nrow=nrow, padding=padding, square_image=square_image).transpose((<NUM_LIT:1>, <NUM_LIT:2>, <NUM_LIT:0>))<EOL><DEDENT>elif img.dtype == np.float32 or img.dtype == np.float64:<EOL><INDENT>min_val = img.min().asscalar()<EOL>max_val = img.max().asscalar()<EOL>if min_val < <NUM_LIT:0.0>:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>'.format(min_val))<EOL><DEDENT>if max_val > <NUM_LIT:1.0>:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>'.format(max_val))<EOL><DEDENT>img = make_image_grid(img, nrow=nrow, padding=padding, square_image=square_image) * <NUM_LIT><EOL>return img.astype(np.uint8).transpose((<NUM_LIT:1>, <NUM_LIT:2>, <NUM_LIT:0>))<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>'.format(str(img.dtype)))<EOL><DEDENT>
Given an image of format HW, CHW, or NCHW, returns a image of format HWC.
    If the input is a batch of images, a grid of images is made by stitching them together.
    If data type is float, values must be in the range [0, 1], and then they are rescaled to
    range [0, 255]. If data type is 'uint8`, values are unchanged.