def matrix(self, qubits: Iterable[raw_types.Qid] | None = None) -> np.ndarray:
        """Returns the matrix of this PauliSum in computational basis of qubits.

        Args:
            qubits: Ordered collection of qubits that determine the subspace
                in which the matrix representation of the Pauli sum is to
                be computed. If none is provided the default ordering of
                `self.qubits` is used.  Qubits present in `qubits` but absent from
                `self.qubits` are acted on by the identity.

        Returns:
            np.ndarray representing the matrix of this PauliSum expression.

        Raises:
            TypeError: if any of the gates in self does not provide a unitary.
        """

        qubits = self.qubits if qubits is None else tuple(qubits)
        num_qubits = len(qubits)
        num_dim = 2**num_qubits
        result = np.zeros((num_dim, num_dim), dtype=np.complex128)
        for vec, coeff in self._linear_dict.items():
            op = _pauli_string_from_unit(vec)
            result += coeff * op.matrix(qubits)
        return result
Returns the matrix of this PauliSum in computational basis of qubits.

        Args:
            qubits: Ordered collection of qubits that determine the subspace
                in which the matrix representation of the Pauli sum is to
                be computed. If none is provided the default ordering of
                `self.qubits` is used.  Qubits present in `qubits` but absent from
                `self.qubits` are acted on by the identity.

        Returns:
            np.ndarray representing the matrix of this PauliSum expression.

        Raises:
            TypeError: if any of the gates in self does not provide a unitary.
        
cirq-core/cirq/ops/linear_combinations.py