How do I output a Cirq gate as a Numpy array? For example, I would like to print a Pauli X gate cirq.X
as
numpy.array([[0,1],[1,0]])
Thank you.
Quantum Computing Stack Exchange is a question and answer site for engineers, scientists, programmers, and computing professionals interested in quantum computing. It only takes a minute to sign up.
Sign up to join this communityHow do I output a Cirq gate as a Numpy array? For example, I would like to print a Pauli X gate cirq.X
as
numpy.array([[0,1],[1,0]])
Thank you.
This can be done by calling cirq.unitary
.
>>> import cirq
>>> cirq.unitary(cirq.X)
array([[0.+0.j, 1.+0.j],
[1.+0.j, 0.+0.j]])
cirq.unitary()
is mentioned in the tutorial page, so that's my bad.) Also, details of the API are sometimes located only in their source code, so I found it a bit difficult to learn Cirq. I think extensive tutorial videos on Youtube would be very helpful.
$\endgroup$
– user3886914
Oct 15 '20 at 4:57