# How to code a projector operator in qiskit?

I'm new to qiskit and I want to know how do I define a projector operator in qiskit? Specifically, I have prepared a 3 qubit system, and after applying a whole lot of gates and measuring it in a state vector simulator, I have to apply the projector operator $$|0\rangle_{1}|0\rangle_{2} \langle0|_{1}\langle0|_{2}$$ on the state that I get after I measured all the qubits in the circuit. I do know the physics and math behind it, and the tensor product it represents but I'm unable to code this successfully. I was thinking maybe a 4x4 matrix representation of this operator might help but I'm not sure about it.

So I'm asking 2 questions here-

1. How do I define a projector operator like this in qiskit
2. How do I apply that operator to a state that I have measured with a state vector simulator?

So, there actually is a method called to_operator() for the class Statevector which takes a statevector and converts it into a projector operator. Here is the code to write your specific projector operator:

from qiskit.quantum_info import Statevector
zero = Statevector([1,0])
zero_state = zero.tensor(zero) # or zero_state = Statevector([1,0,0,0])
projector = zero_state.to_operator()


As you can see, you can input a state as a python list, or as a numpy array. If you print this projector, you will get the following output:

Then, after making your operator, you can use the method evolve() to apply the projector operator on a statevector:

statevector.evolve(projector)