# cirq.MatrixGate¶

class cirq.MatrixGate(matrix: numpy.ndarray, *, qid_shape: Optional[Iterable[int]] = None)[source]

A unitary qubit or qudit gate defined entirely by its matrix.

__init__(matrix: numpy.ndarray, *, qid_shape: Optional[Iterable[int]] = None) → None[source]

Initializes a matrix gate.

Parameters
• matrix – The matrix that defines the gate.

• qid_shape – The shape of state tensor that the matrix applies to. If not specified, this value is inferred by assuming that the matrix is supposed to apply to qubits.