openfermion.linalg.expectation

Compute the expectation value of an operator with a state.

Used in the notebooks

Used in the tutorials

operator(scipy.sparse.spmatrix or scipy.sparse.linalg.LinearOperator): The operator whose expectation value is desired. state(numpy.ndarray or scipy.sparse.spmatrix): A numpy array representing a pure state or a sparse matrix representing a density matrix. If operator is a LinearOperator, then this must be a numpy array.

A complex number giving the expectation value.

ValueError Input state has invalid format.