
import numpy as np

def mean(X, ignore_nan=False, X_thr=None):
    """Compute the mean value from a forecast ensemble field.

    Parameters
    ----------
    X : array_like
        Array of shape (n_members,m,n) containing an ensemble of forecast
        fields of shape (m,n).
    ignore_nan : bool
        If True, ignore nan values.
    X_thr : float
        Optional threshold for computing the ensemble mean. Values below X_thr
        are ignored.

    Returns
    -------
    out : ndarray
        Array of shape (m,n) containing the ensemble mean.
    """
    if ignore_nan or X_thr is not None:
        if X_thr is not None:
            X = X.copy()
            X[X < X_thr] = np.nan

        return np.nanmean(X, axis=0)
    else:
        return np.mean(X, axis=0)

def excprob(X, X_thr, ignore_nan=False):
    """For a given forecast ensemble field, compute exceedance probabilities
    for the given intensity thresholds.

    Parameters
    ----------
    X : array_like
        Array of shape (k,m,n,...) containing an k-member ensemble of forecasts
        with shape (m,n,...).
    X_thr : a sequence of floats
        Intensity thresholds for which the exceedance probabilities are
        computed.
    ignore_nan : bool
        If True, ignore nan values.

    Returns
    -------
    out : ndarray
        Array of shape (len(X_thr),m,n) containing the exceedance probabilities 
        for the given intensity thresholds.
    """
    P = []

    for x in X_thr:
        X_ = X.copy()

        X_[X_ >= x] = 1.0
        X_[X_ <  x] = 0.0

        if ignore_nan:
            P.append(np.nanmean(X_, axis=0))
        else:
            P.append(np.mean(X_, axis=0))

    return np.stack(P)

@@ -1459,16 +1459,131 @@
 P = %5B%5D%0A%0A
+    if np.isscalar(X_thr):%0A        X_thr = %5BX_thr%5D%0A        scalar_thr = True%0A    else:%0A        scalar_thr = False%0A%0A
     for 
@@ -1803,23 +1803,80 @@
     
-return np.stack(P)
+if not scalar_thr:%0A        return np.stack(P)%0A    else:%0A        return P%5B0%5D
 %0A

Allow scalar input for the excprob intensity threshold