# Print data() with statevector and qasm simulator - Qiskit

I am new to Qiskit and I am trying to implement some very simple 1-qubit gates.

I want to initialize the state of the qubit (to 0 and then to 1) and then apply the gate and print the new state of the qubit.

def I(input):

q = QuantumRegister(1)
c = ClassicalRegister(1)
qc = QuantumCircuit(q, c)

if input == '1': #if input = 1, initialize the qubit to 1
qc.x(q[0])

qc.iden(q[0] )

qc.measure( q[0], c[0])

backend = Aer.get_backend('statevector_simulator')
result = qiskit.execute(qc, backend=backend, shots=1).result()
output = result.data(qc)

return output

And I call the function like this:

print('\nResults for the Iden gate')
for input in ['0','1']:
print('    Input',input,'gives output',I(input))

Now the output of all this is:

Results for the Iden gate
Input 0 gives output {'statevector': [[1.0, 0.0], [0.0, 0.0]], 'counts': {'0x0': 1}}
Input 1 gives output {'statevector': [[0.0, 0.0], [1.0, 0.0]], 'counts': {'0x1': 1}}

I know that the data() function returns the Instruction object, a list of Qubits objects and a list of classical bits with the order they added. So here the second list is the list with the qubits.

But when the qubit is '0', shouldn't it return a list with all 0? I am not sure about the meaning of the output.

$$(1+0i)\vert 0 \rangle + (0+0i)\vert 1 \rangle$$, which is the same as saying the qubit is in the $$\vert 0 \rangle$$ state.
• It works in the same way as the one qubit case, only now your basis states are in terms of 2 qubits. This means the coefficients correspond to $\vert 00 \rangle,\vert 01 \rangle, \vert 10\rangle, \vert 11 \rangle$ respectively. The order of this is simply counting up in binary, Dec 21, 2019 at 15:38