Compute the expectation value of an operator with a state.
openfermion.linalg.expectation(
operator, state
)
Used in the notebooks
Args |
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.
|
Returns |
A complex number giving the expectation value.
|
Raises |
ValueError
|
Input state has invalid format.
|