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 ) –

    Boolean denoting whether the returned basis vectors will have all real entries or not.

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

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

Returns:

  • list[ndarray]

    A list of dim orthonormal basis vectors, each of dimension dim.

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.07861349,  0.42600218,  0.80452385, -0.4063046 ]), array([-0.43084736, -0.02521638, -0.36185678, -0.82631371]), array([ 0.45343798, -0.80462765,  0.22499045, -0.31039915]), array([ 0.77626315,  0.41286876, -0.41373945, -0.23616643])]

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: Boolean denoting whether the returned basis vectors will have all real entries or not.
        seed: A seed used to instantiate numpy's random number generator.

    Returns:
        A list of `dim` orthonormal basis vectors, each of dimension `dim`.

    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)]