rand.random_state_vector

Generate random state vector.

Module Contents

Functions

random_state_vector(dim[, is_real, k_param])

Generate a random pure state vector.

rand.random_state_vector.random_state_vector(dim, is_real=False, k_param=0)

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.rand import random_state_vector
>>> vec = random_state_vector(2)
>>> vec 
array([[0.78645233+0.16239043j],
       [0.56649582+0.18494478j]])

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 (list[int] | int) – The number of rows (and columns) of the unitary matrix.

  • is_real (bool) – Boolean denoting whether the returned matrix has real entries or not. Default is False.

  • k_param (int) – Default 0.

Returns:

A dim-by-dim random unitary matrix.

Return type:

numpy.ndarray