Skip to main content

The stats_arrays package provides a standard NumPy array interface for defining uncertain parameters used in models, and classes for Monte Carlo sampling. It also plays well with others.

Motivation

  • Want a consistent interface to SciPy and NumPy statistical function
  • Want to be able to quickly load and save many parameter uncertainty distribution definitions in a portable format
  • Want to manipulate and switch parameter uncertainty distributions and variables
  • Want simple Monte Carlo random number generators that return a vector of parameter values to be fed into uncertainty or sensitivity analysis
  • Want something simple, extensible, documented and tested

The `stats_arrays package was originally developed for the Brightway2 life cycle assessment framework, but can be applied to any stochastic model.

Example

>>> from stats_arrays import *
>>> my_variables = UncertaintyBase.from_dicts(
...     {'loc': 2, 'scale': 0.5, 'uncertainty_type': NormalUncertainty.id},
...     {'loc': 1.5, 'minimum': 0, 'maximum': 10, 'uncertainty_type': TriangularUncertainty.id}
... )
>>> my_variables
array([(2.0, 0.5, nan, nan, nan, False, 3),
       (1.5, nan, nan, 0.0, 10.0, False, 5)],
    dtype=[('loc', '<f8'), ('scale', '<f8'), ('shape', '<f8'),
           ('minimum', '<f8'), ('maximum', '<f8'), ('negative', '?'),
           ('uncertainty_type', 'u1')])
>>> my_rng = MCRandomNumberGenerator(my_variables)
>>> my_rng.next()
array([ 2.74414022,  3.54748507])
>>> # can also be used as an interator
>>> zip(my_rng, xrange(10))
[(array([ 2.96893108,  2.90654471]), 0),
 (array([ 2.31190619,  1.49471845]), 1),
 (array([ 3.02026168,  3.33696367]), 2),
 (array([ 2.04775418,  3.68356226]), 3),
 (array([ 2.61976694,  7.0149952 ]), 4),
 (array([ 1.79914025,  6.55264372]), 5),
 (array([ 2.2389968 ,  1.11165296]), 6),
 (array([ 1.69236527,  3.24463981]), 7),
 (array([ 1.77750176,  1.90119991]), 8),
 (array([ 2.32664152,  0.84490754]), 9)]

Type checking

stats_arrays is a typed library. It ships a py.typed marker (PEP 561), so mypy, pyright and friends will use its inline annotations rather than treating the package as untyped. Two aliases are exported for annotating your own code:

from typing import Optional

from stats_arrays import NormalUncertainty, ParamsArray, StatisticsResult

params: ParamsArray = NormalUncertainty.from_dicts({"loc": 2.0, "scale": 0.5})
stats: StatisticsResult = NormalUncertainty.statistics(params)
mean: Optional[float] = stats["mean"]

StatisticsResult is a TypedDict with the keys mean, mode, median, lower and upper; a statistic that is undefined for a given distribution is None, never absent.

Note that the field layout of a params array is not expressible in NumPy's typing system, so ParamsArray documents intent and field access (params["loc"]) stays untyped.

More

Metadata

Release files for stats-arrays 5.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stats-arrays 5.0.1
File Size Uploaded Provenance Actions
stats_arrays-5.0.1.tar.gz 69.1 kB With provenance Details for stats_arrays-5.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for stats-arrays 5.0.1
File Interpreter ABI Platform Actions
stats_arrays-5.0.1-py3-none-any.whl Python 3 none any Details for stats_arrays-5.0.1-py3-none-any.whl

Total release size: 111.8 kB

Release files / stats_arrays-5.0.1.tar.gz

Download URL stats_arrays-5.0.1.tar.gz
Size 69.1 kB
Tags Source
SHA-256 checksum
How to use checksums
cede6970e91029d80912d25bec1ac9515e51013268dc9f8326bcf111c8b14ee0
BLAKE2b-256 checksum
How to use checksums
0443ee86035171818d659318f3fe2046db444b775fac6ed5a7f7cef07b212069
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / stats_arrays-5.0.1-py3-none-any.whl

Download URL stats_arrays-5.0.1-py3-none-any.whl
Size 42.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e95b2603b7f2b07397a11a4247018b7012b3f2c0625ba0ecc4aea3fa8e3a09fa
BLAKE2b-256 checksum
How to use checksums
f0d34c9b49e01cc5fa0587bfd301f440639568d68d0755da0d2e161c8a164cc0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for stats-arrays 5.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for stats_arrays-5.0.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

5.0.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page