toqito.random.random_state_vector

toqito.random.random_state_vector(dim: list[int] | int, is_real: bool = False, k_param: int = 0) → np.ndarray[source]

Generate a random pure state vector.

Examples

We may generate a random state vector. For instance, here is an example where we can generate a \(2\)-dimensional random state vector.

>>> from toqito.random import random_state_vector
>>> vec = random_state_vector(2)
>>> vec
[[0.50993973+0.15292408j],
 [0.27787332+0.79960122j]]

We can verify that this is in fact a valid state vector by computing the corresponding density matrix of the vector and checking if the density matrix is pure.

>>> from toqito.state_props import is_pure
>>> dm = vec.conj().T * vec
>>> is_pure(dm)
True
Parameters:
  • dim – The number of rows (and columns) of the unitary matrix.
  • is_real – Boolean denoting whether the returned matrix has real entries or not. Default is False.
  • k_param – Default 0.
Returns:

A dim-by-dim random unitary matrix.