Skip to main content

Ensemble averages

Project description


CI Documentation Status Conda Version PyPi release



enstat is a library to facilitate the computation of ensemble averages (and their variances) or histograms.

The key feature is that a class stores the sum of the first and second statistical moments and the number of samples. This gives access to the mean (and variance) at all times, while you can keep adding samples.

For the histogram something similar holds, but this time the count per bin is stored.

Ensemble average

Suppose that we have 100 realisations, each with 1000 'blocks', and we want to know the ensemble average of each block:

import enstat

ensemble = enstat.static()

for realisation in range(100):

    sample = np.random.random(1000)
    ensemble += sample


Ensemble histogram

Same example, but now we want the histogram for pre-defined bins:

import enstat

bin_edges = np.linspace(0, 1, 11)
hist = enstat.histogram(bin_edges=bin_edges)

for realisation in range(100):

    sample = np.random.random(1000)
    hist += sample


which prints the probability density of each bin (so list of values around 0.1 for these bins).

Histogram: bins and plotting

The histogram class contains two nice features.

  1. It has several bin algorithms that NumPy does not have.

  2. It can be used for plotting with an ultra-sort interface, for example:

    import enstat
    import matplotlib.pyplot as plt
    data = np.random.random(1000)
    hist = enstat.histogram.from_data(data, bins=10, mode="log")
    fig, ax = plt.subplots()
    ax.plot(hist.x, hist.p)

    You can even use ax.plot(*hist.plot).


  • Using conda

    conda install -c conda-forge enstat
  • Using PyPi

    python -m pip install enstat


This library is free to use under the MIT license. Any additions are very much appreciated. As always, the code comes with no guarantee. None of the developers can be held responsible for possible mistakes.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

enstat-0.8.0.tar.gz (17.8 kB view hashes)

Uploaded Source

Built Distribution

enstat-0.8.0-py3-none-any.whl (11.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page