I am getting confused as to how to perform gate operations using matrices and am hoping someone will help me walk through this example.

Say I want to perform a Pauli-X gate on the 3rd qubit in a 3-qubit system. That operation would be:

U = I ⊗ I ⊗ X

Then say I have the state $|001\rangle$ so after applying U the state would become $|000\rangle$. I am trying to use Python and NumPy to calculate this but I believe I am missing something.

i = np.array([[1, 0],
              [0, 1]])

x = np.array([[0, 1],
              [1, 0]])

state_0 = np.array([[1],
state_1 = np.array([[0],

x_3 = np.kron(np.kron(i,i),x)

v = np.kron(np.kron(state_0, state_0), state_1)


This code outputs:


I am unsure if this output is correct and if it is how would I see this as the state $|000\rangle$? Any clarifications would be very useful! Thank you!


1 Answer 1


You can use the same tools you used to get this output to check that it is correct: the state $|000\rangle$ would be represented as tensor product $|0\rangle \otimes |0\rangle \otimes |0\rangle$, which in your Python notation would be np.kron(np.kron(state_0, state_0), state_0). This should give you the same column vector you got from running your code, with the first element 1 and the rest of them 0s.

  • 1
    $\begingroup$ Continuing this: do np.kron(np.kron(state_0, state_0), state_1) then np.kron(np.kron(state_0, state_1), state_0) and so on and see they give you other column vectors with only a single nonzero entry somewhere. You should see the relation from where the nonzero is and what the bit string is from that. $\endgroup$
    – AHusain
    Jun 12, 2019 at 22:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.