0
$\begingroup$

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.

$\endgroup$
2
$\begingroup$

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]])
$\endgroup$
3
  • $\begingroup$ Thanks a lot! Compared to Qiskit, I found Cirq has very little documentation. Do you have any recommendation for getting familiar with Cirq? $\endgroup$ – user3886914 Oct 14 '20 at 15:59
  • $\begingroup$ @user3886914 Which types of documentation do you feel are missing? E.g. there's a decent API reference at readthedocs, but not a lot of task-oriented content like a guided tutorial to do goal X. $\endgroup$ – Craig Gidney Oct 14 '20 at 16:42
  • $\begingroup$ @CraigGidney Compared to Qiskit, I feel that Cirq's tutorial and documents are too short. (Though, I just realized 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.