from qiskit import *

# set up circuit (no measurements required)
qc = QuantumCircuit(2)
qc.x(0) # qubits numbered from the right, so qubit 0 is the qubit on the right
qc.z(1) # and qubit 1 is on the left

# set up simulator that returns unitary matrix
backend = Aer.get_backend('unitary_simulator')

# run the circuit to get the matrix
gate = execute(qc,backend).result().get_unitary()

# now we use some fanciness to display it in latex
from IPython.display import display, Markdown, Latex
gate_latex = '\\begin{pmatrix}'
for line in gate:
    for element in line:
        gate_latex += str(element) + '&'
    gate_latex  = gate_latex[0:-1]
    gate_latex +=  '\\\\'
gate_latex  = gate_latex[0:-2]
gate_latex += '\end{pmatrix}'
display(Markdown(gate_latex))