mean_xy_data(xdata, ydata, sigma=None, shots=None, method='sample')[source]

Return (x, y_mean, sigma) data.

The mean is taken over all \(y\) data values with the same \(x\) data value using the specified method. For each \(x\) the mean \(\overline{y}\) and variance \(\sigma^2\) are computed as

  • "sample" (default): Sample mean and variance

    • \(\overline{y} = \sum_{i=1}^N y_i / N\),

    • \(\sigma^2 = \sum_{i=1}^N ((\overline{y} - y_i)^2) / N\)

  • "iwv": Inverse-weighted variance

    • \(\overline{y} = (\sum_{i=1}^N y_i / \sigma_i^2 ) \sigma^2\)

    • \(\sigma^2 = 1 / (\sum_{i=1}^N 1 / \sigma_i^2)\)

  • "shots_weighted_variance": Sample mean and variance with weights from shots

    • \(\overline{y} = \sum_{i=1}^N n_i y_i / M\),

    • \(\sigma^2 = \sum_{i=1}^N (n_i \sigma_i / M)^2\), where \(n_i\) is the number of shots per data point and \(M = \sum_{i=1}^N n_i\) is a total number of shots from different circuit execution at the same \(x\) value. If shots is not provided, this applies uniform weights to all values.

Deprecated since version 0.6_pending: The function qiskit_experiments.curve_analysis.utils.mean_xy_data() is pending deprecation as of qiskit-experiments 0.6. It will be marked deprecated in a future release, and then removed no earlier than 3 months after the release date. The curve data representation has been replaced by the DataFrame format.

  • xdata (ndarray) – 1D or 2D array of xdata from curve_fit_data or multi_curve_fit_data

  • ydata (ndarray) – array of ydata returned from curve_fit_data or multi_curve_fit_data

  • sigma (ndarray | None) – Optional, array of standard deviations in ydata.

  • shots (ndarray | None) – Optional, array of shots used to get a data point.

  • method (str) – The method to use for computing y means and standard deviations sigma (default: “sample”).


(x, y_mean, sigma, shots), where x is an arrays of unique x-values, y is an array of sample mean y-values, sigma is an array of sample standard deviation of y values, and shots are the total number of experiment shots used to evaluate the data point. If shots in the function call is None, the numbers appear in the returned value will represent just a number of duplicated x value entries.

Return type:



QiskitError – If the “ivw” method is used without providing a sigma.