qrisp.operators.qubit.QubitOperator.to_array#

QubitOperator.to_array(factor_amount=None)[source]#

Returns a numpy array representing the operator

\[O=\sum_i\alpha_i\bigotimes_{j=0}^{n-1}O_{ij}\]

where \(O_{ij}\in\{X,Y,Z,A,C,P_0,P_1,I\}\).

Parameters:
factor_amountint, optional

The amount of factors \(n\) to represent this matrix. The matrix will have the dimension \(2^n \times 2^n\), where n is the amount of factors. By default the minimal number \(n\) is chosen.

Returns:
np.ndarray

The array representing the operator.

Examples

>>> from qrisp.operators import *
>>> O = X(0)*X(1) + 2*P0(0)*P0(1) + 3*P1(0)*P1(1)
>>> O.to_array()
matrix([[2.+0.j, 0.+0.j, 0.+0.j, 1.+0.j],
        [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],
        [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],
        [1.+0.j, 0.+0.j, 0.+0.j, 3.+0.j]])