Skip to content

random_orthonormal_basis

Generates a random orthonormal basis.

random_orthonormal_basis

random_orthonormal_basis(
    dim: int, is_real: bool = False, seed: int | None = None
) -> list[ndarray]

Generate a real random orthonormal basis of given dimension \(d\).

The basis is generated from the columns of a random unitary matrix of the same dimension as the columns of a unitary matrix typically form an orthonormal basis 1.

Parameters:

  • dim (int) –

    Number of elements in the random orthonormal basis.

  • is_real (bool, default: False ) –

    Bool

  • seed (int | None, default: None ) –

    A seed used to instantiate numpy's random number generator.

Examples:

To generate a random orthonormal basis of dimension \(4\),

from toqito.rand import random_orthonormal_basis

print(random_orthonormal_basis(4, is_real = True))
[array([ 0.3463865 ,  0.26523867,  0.33694333, -0.83434647]), array([ 0.61416497,  0.60698551, -0.42082115,  0.27799196]), array([ 0.61546291, -0.74907298, -0.23285148, -0.07665021]), array([ 0.35216924, -0.0103294 ,  0.80941889,  0.46979909])]

It is also possible to add a seed for reproducibility.

from toqito.rand import random_orthonormal_basis

print(random_orthonormal_basis(2, is_real=True, seed=42))
[array([0.37621414, 0.92653274]), array([-0.92653274,  0.37621414])]

References

1 Mathematics, Stack. Why do the columns of a unitary matrix form an orthonormal basis?. link.

Source code in toqito/rand/random_orthonormal_basis.py
def random_orthonormal_basis(dim: int, is_real: bool = False, seed: int | None = None) -> list[np.ndarray]:
    r"""Generate a real random orthonormal basis of given dimension \(d\).

    The basis is generated from the columns of a random unitary matrix of the same dimension
    as the columns of a unitary matrix typically form an orthonormal basis [@se1688950].

    Args:
        dim: Number of elements in the random orthonormal basis.
        is_real: Bool
        seed: A seed used to instantiate numpy's random number generator.

    Examples:
        To generate a random orthonormal basis of dimension \(4\),

        ```python exec="1" source="above" result="text"
        from toqito.rand import random_orthonormal_basis

        print(random_orthonormal_basis(4, is_real = True))
        ```

        It is also possible to add a seed for reproducibility.

        ```python exec="1" source="above" result="text"
        from toqito.rand import random_orthonormal_basis

        print(random_orthonormal_basis(2, is_real=True, seed=42))
        ```

    """
    random_mat = random_unitary(dim, is_real, seed)
    return [random_mat[:, i] for i in range(dim)]