Qiskit Textbook, Chapter 2, Section 2.2. Single Qubit Gates on Multi-Qubit Statevectors (here).
In here, they have described that: If we want to apply a gate to only one qubit at a time (such as in the circuit below), we describe this using tensor product with the identity matrix, e.g.: $X\otimes I$.
By executing the given code, the tensor product matrix generated corresponds to when X-gate is applied to qubit 1 in circuit.
qc = QuantumCircuit(2)
qc.x(1)
qc.draw()
# Simulate the unitary
usim = Aer.get_backend('unitary_simulator')
qobj = assemble(qc)
unitary = usim.run(qobj).result().get_unitary()
# Display the results:
array_to_latex(unitary, pretext="\\text{Circuit = } ")
The output is:
When I tried to change the $X$ gate position to qubit 0 (qc.x(0)
) then the tensor product matrix is changed (refer to image attached below). My doubt is: in this case how is the tensor product calculated, shouldn't it be the same?