Skip to content

cnot

CNOT matrix generates the CNOT operator matrix.

cnot

cnot() -> ndarray

Produce the CNOT matrix 1.

The CNOT matrix is defined as

\[ \text{CNOT} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix}. \]

Returns:

  • ndarray

    The CNOT matrix.

Examples:

from toqito.matrices import cnot

print(cnot())
[[1 0 0 0]
 [0 1 0 0]
 [0 0 0 1]
 [0 0 1 0]]

References

1 Wikipedia. Controlled NOT gate. link.

Source code in toqito/matrices/cnot.py
def cnot() -> np.ndarray:
    r"""Produce the CNOT matrix [@wikipediacnot].

    The CNOT matrix is defined as

    \[
        \text{CNOT} =
        \begin{pmatrix}
            1 & 0 & 0 & 0 \\
            0 & 1 & 0 & 0 \\
            0 & 0 & 0 & 1 \\
            0 & 0 & 1 & 0
        \end{pmatrix}.
    \]

    Returns:
        The CNOT matrix.

    Examples:
        ```python exec="1" source="above" result="text"
        from toqito.matrices import cnot

        print(cnot())
        ```

    """
    return np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]])