def tan_rand(q, seed=9):
    """Find a random vector in the tangent space of the n sphere

    This function will find a random orthogonal vector to q.

    Parameters
    ----------
    q
        (n+1,) array which is in the n-sphere

    Returns
    -------
    qd
        (n+1,) array which is orthogonal to n-sphere and also random

    """
    # probably need a check in case we get a parallel vector
    rs = np.random.RandomState(seed)
    rvec = rs.rand(q.shape[0])

    qd = np.cross(rvec, q)
    qd = qd / np.linalg.norm(qd)

    while np.dot(q, qd) > 1e-6:
        rvec = rs.rand(q.shape[0])
        qd = np.cross(rvec, q)
        qd = qd / np.linalg.norm(qd)

    return qd
def tan_rand ( q , seed = 9 ) : rs = np . random . RandomState ( seed ) rvec = rs . rand ( q . shape [ 0 ] ) qd = np . cross ( rvec , q ) qd = qd / np . linalg . norm ( qd ) while np . dot ( q , qd ) > 1e-6 : rvec = rs . rand ( q . shape [ 0 ] ) qd = np . cross ( rvec , q ) qd = qd / np . linalg . norm ( qd ) return qd
Find a random vector in the tangent space of the n sphere

    This function will find a random orthogonal vector to q.

    Parameters
    ----------
    q
        (n+1,) array which is in the n-sphere

    Returns
    -------
    qd
        (n+1,) array which is orthogonal to n-sphere and also random