def batchify_shape(shape, dims=None):
    """
    Convert the leading dimension to a batch dimension of None.
    :param shape: shape of an array.
    :param dims: the final dimension of the shape after batchifying. If left None, will be len(shape)
    :return: a new shape list with a leading None for the batch dimension
    """
    dims = dims or len(shape)
    return [None] + list(shape[len(shape) - dims + 1:])
