def impad(img, shape, pad_val=<NUM_LIT:0>):
if not isinstance(pad_val, (int, float)):<EOL><INDENT>assert len(pad_val) == img.shape[-<NUM_LIT:1>]<EOL><DEDENT>if len(shape) < len(img.shape):<EOL><INDENT>shape = shape + (img.shape[-<NUM_LIT:1>], )<EOL><DEDENT>assert len(shape) == len(img.shape)<EOL>for i in range(len(shape) - <NUM_LIT:1>):<EOL><INDENT>assert shape[i] >= img.shape[i]<EOL><DEDENT>pad = np.empty(shape, dtype=img.dtype)<EOL>pad[...] = pad_val<EOL>pad[:img.shape[<NUM_LIT:0>], :img.shape[<NUM_LIT:1>], ...] = img<EOL>return pad<EOL>
Pad an image to a certain shape.

    Args:
        img (ndarray): Image to be padded.
        shape (tuple): Expected padding shape.
        pad_val (number or sequence): Values to be filled in padding areas.

    Returns:
        ndarray: The padded image.