def average_data(counts, observable):
if not isinstance(observable, dict):<EOL><INDENT>observable = make_dict_observable(observable)<EOL><DEDENT>temp = <NUM_LIT:0><EOL>tot = sum(counts.values())<EOL>for key in counts:<EOL><INDENT>if key in observable:<EOL><INDENT>temp += counts[key] * observable[key] / tot<EOL><DEDENT><DEDENT>return temp<EOL>
Compute the mean value of an diagonal observable.

    Takes in a diagonal observable in dictionary, list or matrix format and then
    calculates the sum_i value(i) P(i) where value(i) is the value of the
    observable for state i.

    Args:
        counts (dict): a dict of outcomes from an experiment
        observable (dict or matrix or list): The observable to be averaged over.
        As an example, ZZ on qubits can be given as:
        * dict: {"00": 1, "11": 1, "01": -1, "10": -1}
        * matrix: [[1, 0, 0, 0], [0, -1, 0, 0, ], [0, 0, -1, 0], [0, 0, 0, 1]]
        * matrix diagonal (list): [1, -1, -1, 1]

    Returns:
        Double: Average of the observable