qiskit/tools/apps/optimization.py
def measure_pauli_z(data, pauli):
    """Compute the expectation value of Z.

    Z is represented by Z^v where v has lenght number of qubits and is 1
    if Z is present and 0 otherwise.

    Args:
        data (dict): a dictionary of the form data = {'00000': 10}
        pauli (Pauli): a Pauli object
    Returns:
        float: Expected value of pauli given data
 """
    observable = 0
    tot = sum(data.values())
    for key in data:
        value = 1
        for j in range(pauli.numberofqubits):
            if ((pauli.v[j] == 1 or pauli.w[j] == 1) and
                    key[pauli.numberofqubits - j - 1] == '1'):
                value = -value

        observable = observable + value * data[key] / tot
    return observable
Compute the expectation value of Z.

    Z is represented by Z^v where v has lenght number of qubits and is 1
    if Z is present and 0 otherwise.

    Args:
        data (dict): a dictionary of the form data = {'00000': 10}
        pauli (Pauli): a Pauli object
    Returns:
        float: Expected value of pauli given data
 
Compute the expectation value of Z.
Z is represented by Z^v where v has lenght number of qubits and is 1
if Z is present and 0 otherwise.
Compute the expectation value of Z . Z is represented by Z^v where v has lenght number of qubits and is 1 if Z is present and 0 otherwise .
def measure_pauli_z(data, pauli):
    observable = 0
    tot = sum(data.values())
    for key in data:
        value = 1
        for j in range(pauli.numberofqubits):
            if ((pauli.v[j] == 1 or pauli.w[j] == 1) and
                    key[pauli.numberofqubits - j - 1] == '1'):
                value = -value
        observable = observable + value * data[key] / tot
    return observable
def measure_pauli_z ( data , pauli ) : observable = 0 tot = sum ( data . values ( ) ) for key in data : value = 1 for j in range ( pauli . numberofqubits ) : if ( ( pauli . v [ j ] == 1 or pauli . w [ j ] == 1 ) and key [ pauli . numberofqubits - j - 1 ] == '1' ) : value = - value observable = observable + value * data [ key ] / tot return observable
Compute the expectation value of Z.
Compute the expectation value of Z .
"""Compute the expectation value of Z.

    Z is represented by Z^v where v has lenght number of qubits and is 1
    if Z is present and 0 otherwise.

    Args:
        data (dict): a dictionary of the form data = {'00000': 10}
        pauli (Pauli): a Pauli object
    Returns:
        float: Expected value of pauli given data
 """
Expected value of pauli given data
Expected value of pauli given data
float
data
None
pauli
a Pauli object
a Pauli object