qiskit/quantum_info/operators/pauli.py
def to_spmatrix(self):
        r"""
        Convert Pauli to a sparse matrix representation (CSR format).

        Order is q_{n-1} .... q_0, i.e., $P_{n-1} \otimes ... P_0$

        Returns:
            scipy.sparse.csr_matrix: a sparse matrix with CSR format that
            represnets the pauli.
        """
        mat = sparse.coo_matrix(1)
        for z, x in zip(self._z, self._x):
            if not z and not x:  # I
                mat = sparse.bmat([[mat, None], [None, mat]], format='coo')
            elif z and not x:  # Z
                mat = sparse.bmat([[mat, None], [None, -mat]], format='coo')
            elif not z and x:  # X
                mat = sparse.bmat([[None, mat], [mat, None]], format='coo')
            else:  # Y
                mat = mat * 1j
                mat = sparse.bmat([[None, -mat], [mat, None]], format='coo')

        return mat.tocsr()
def to_spmatrix(self):
        r"""
        Convert Pauli to a sparse matrix representation (CSR format).

        Order is q_{n-1} .... q_0, i.e., $P_{n-1} \otimes ... P_0$

        Returns:
            scipy.sparse.csr_matrix: a sparse matrix with CSR format that
            represnets the pauli.
        """
        mat = sparse.coo_matrix(1)
        for z, x in zip(self._z, self._x):
            if not z and not x:  # I
                mat = sparse.bmat([[mat, None], [None, mat]], format='coo')
            elif z and not x:  # Z
                mat = sparse.bmat([[mat, None], [None, -mat]], format='coo')
            elif not z and x:  # X
                mat = sparse.bmat([[None, mat], [mat, None]], format='coo')
            else:  # Y
                mat = mat * 1j
                mat = sparse.bmat([[None, -mat], [mat, None]], format='coo')

        return mat.tocsr()
r"""
        Convert Pauli to a sparse matrix representation (CSR format).

        Order is q_{n-1} .... q_0, i.e., $P_{n-1} \otimes ... P_0$

        Returns:
            scipy.sparse.csr_matrix: a sparse matrix with CSR format that
            represnets the pauli.