def vector_magnitude(vec, axis=None):
    """
    Calculate the mangitude of a real vector. If axis is provided,
    vec is treated as an array of vectors and reduced along the
    given axis. This will work on arrays of any dimension.
    """
    return (vec * vec).sum(axis=axis) ** 0.5