Skip to Content

PMEAN

Overview

The PMEAN function calculates the power mean (also known as the generalized mean) of the input data for a given power p. The power mean is a generalization of the arithmetic, geometric, and harmonic means, and is defined as:

Mp(x1,...,xn)=(1ni=1nxip)1/pM_p(x_1, ..., x_n) = \left(\frac{1}{n} \sum_{i=1}^n x_i^p\right)^{1/p}

where pp is the power parameter, and xix_i are the data values. For p=1p=1, the power mean is the arithmetic mean; for p=0p=0, it is the geometric mean; and for p=1p=-1, it is the harmonic mean. This function flattens the input, ignores non-numeric values, and does not support weights or axis arguments, unlike scipy.stats.pmean. Excel does not have a direct equivalent; this function is a custom implementation for 2D lists.

This example function is provided as-is without any representation of accuracy.

Usage

To use the function in Excel:

=PMEAN(data, p)
  • data (2D list, required): The input data as a 2D list (column or matrix). Non-numeric values are ignored.
  • p (float, required): The power parameter for the mean. Common values: 1 (arithmetic), 0 (geometric), -1 (harmonic).

The function returns a single value (float): the power mean of the input data, or an error message (string) if the input is invalid.

Examples

Example 1: Arithmetic Mean (p=1)

Inputs:

datap
121
34

Excel formula:

=PMEAN({1,2;3,4}, 1)

Expected output:

Result
2.5

Example 2: Geometric Mean (p=0)

Inputs:

datap
120
34

Excel formula:

=PMEAN({1,2;3,4}, 0)

Expected output:

Result
2.2134

Example 3: Harmonic Mean (p=-1)

Inputs:

datap
12-1
34

Excel formula:

=PMEAN({1,2;3,4}, -1)

Expected output:

Result
1.9200

Example 4: Power Mean (p=2)

Inputs:

datap
122
34

Excel formula:

=PMEAN({1,2;3,4}, 2)

Expected output:

Result
2.7386

Python Code

import math def pmean(data, p): """ Computes the power mean (generalized mean) of the input data for a given power p. Flattens the input, ignores non-numeric values, and does not support weights or axis arguments. This example function is provided as-is without any representation of accuracy. """ # Flatten and filter numeric values flat = [] if isinstance(data, (int, float)): return "Two or more data elements are needed" for row in data: for val in row: try: v = float(val) flat.append(v) except (ValueError, TypeError): continue if len(flat) < 2: return "Two or more data elements are needed" n = len(flat) if p == 0: # Geometric mean prod = 1.0 for v in flat: if v <= 0: return "All values must be positive for geometric mean" prod *= v return round(prod ** (1.0 / n), 4) else: try: mean = sum(v ** p for v in flat) / n return round(mean ** (1.0 / p), 4) except Exception as e: return str(e)

Live Notebook

Edit this function in a live notebook.

Live Demo

Last updated on