def positiveaxis(axis, ndim):
    """Positive axis

    Args:
        axis(num): dimension index
        ndim(num): number of dimensions
    Returns:
        num
    """
    if axis < 0:
        axis += ndim
    if axis < 0 or axis >= ndim:
        raise IndexError("axis out of range")
    return axis