Is there any way to obtain the unitary matrix of single way in analytic form?

In numerical form, I could use a workaround like this (i.e. for an X Gate):

>>> from qiskit import QuantumCircuit
>>> qc = QuantumCircuit(1)
>>> qc.x(0)

>>> import qiskit.quantum_info as qi
>>> op = qi.Operator(qc)
>>> print(op.data)
array([[0.+0.j, 1.+0.j],
       [1.+0.j, 0.+0.j]])

But in case of an H gate, it returns this:

array([[ 0.70710678+0.j,  0.70710678+0.j],
       [ 0.70710678+0.j, -0.70710678+0.j]])

Which does not look as nice as... $$ \begin{split}H = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1\\ 1 & -1 \end{pmatrix}\end{split}$$

Is the a way to obtain the operators in this form, from within qiskit?


1 Answer 1


I think your best option here is to use array_to_latex from qiskit.visualization module:

from qiskit.visualization import array_to_latex

u = [
    [ 0.70710678+0.j,  0.70710678+0.j],
    [ 0.70710678+0.j, -0.70710678+0.j]

array_to_latex(u, prefix='H=')

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.