Skip to main content

Repo Docs PyPI license PyPI version Conda (channel only) Code style: ruff uv

cmomy

A Python package to calculate and manipulate Central (co)moments. The main features of cmomy are as follows:

  • numba accelerated computation of central moments and co-moments
  • Routines to combine, and resample central moments.
  • Supports numpy array and xarray DataArray or Dataset based data.
  • Routines to convert between central and raw moments.

Overview

cmomy is an open source package to calculate central moments and co-moments in a numerical stable and direct way. Behind the scenes, cmomy makes use of numba to rapidly calculate moments. A good introduction to the type of formulas used can be found here.

Features

  • Fast calculation of central moments and central co-moments with weights
  • Support for scalar or vector inputs
  • numpy and xarray api's
  • bootstrap resampling

Status

This package is actively used by the author. Please feel free to create a pull request for wanted features and suggestions!

Example usage

>>> import numpy as np
>>> import cmomy
>>> rng = cmomy.default_rng(seed=0)
>>> x = rng.random(100)
>>> m = x.mean()
>>> mom = np.array([((x - m) ** i).mean() for i in range(4)])
>>> c = cmomy.wrap_reduce_vals(x, mom=3, axis=0)

>>> np.testing.assert_allclose(c.cmom(), mom, atol=1e-8)
>>> c.cmom()
array([ 1.    ,  0.    ,  0.0919, -0.0061])

# break up into chunks
>>> c = cmomy.wrap_reduce_vals(x.reshape(-1, 2), mom=3, axis=0)

>>> c
<CentralMomentsArray(mom_ndim=1)>
array([[ 5.0000e+01,  5.3019e-01,  8.0115e-02, -4.3748e-03],
       [ 5.0000e+01,  5.6639e-01,  1.0297e-01, -8.9911e-03]])

# Reduce along an axis
>>> c.reduce(axis=0).cmom()
array([ 1.    ,  0.    ,  0.0919, -0.0061])

# unequal chunks
>>> x0, x1, x2 = x[:20], x[20:60], x[60:]

>>> cs = [cmomy.wrap_reduce_vals(_, mom=3, axis=0) for _ in (x0, x1, x2)]

>>> c = cs[0] + cs[1] + cs[2]

>>> np.testing.assert_allclose(c.cmom(), mom, atol=1e-8)
>>> c.cmom()
array([ 1.    ,  0.    ,  0.0919, -0.0061])

Installation

Use one of the following

pip install cmomy

or

conda install -c conda-forge cmomy

Note on caching

This code makes extensive use of the numba python package. This uses a jit compiler to speed up vital code sections. This means that the first time a function called, it has to compile the underlying code. However, caching has been implemented. Therefore, the very first time you run a function, it may be slow. But all subsequent uses (including other sessions) will be already compiled. You can pre-compile the cmomy by running

python -m cmomy.compile

If you'll be using cmomy in parallel (e.g., using multiprocessing), make sure to pre-compile cmomy, or to turn off caching by setting the environment variable CMOMY_NUMBA_CACHE=0.

Documentation

See the documentation for a look at cmomy in action.

What's new?

See changelog.

License

This is free software. See LICENSE.

This package is used extensively in the newest version of thermoextrap. See here.

Contact

The author can be reached at wpk@nist.gov.

Credits

This package was created using Cookiecutter with the usnistgov/cookiecutter-nist-python template.

Metadata

Release files for cmomy 1.2.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 cmomy 1.2.1
File Size Uploaded Provenance Actions
cmomy-1.2.1.tar.gz 182.2 kB With provenance Details for cmomy-1.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cmomy 1.2.1
File Interpreter ABI Platform Actions
cmomy-1.2.1-py3-none-any.whl Python 3 none any Details for cmomy-1.2.1-py3-none-any.whl

Total release size: 337.7 kB

Release files / cmomy-1.2.1.tar.gz

Download URL cmomy-1.2.1.tar.gz
Size 182.2 kB
Tags Source
SHA-256 checksum
How to use checksums
281308c0f8d25884b71a123e63f68f337bf94a28f417deb6c115c926a51aac84
BLAKE2b-256 checksum
How to use checksums
315b9e8343bafd305e0d66f4fa8f91c7eefa409ba0d21b221ee3e860a0ef2aa4
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 12, 2026.

Transparency log

Release files / cmomy-1.2.1-py3-none-any.whl

Download URL cmomy-1.2.1-py3-none-any.whl
Size 155.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6d94832d90e7c259617eafbc9ac323148578868ad1f1731def782989816d282
BLAKE2b-256 checksum
How to use checksums
b7f7b4924de3f5b25938dabe96285c0e08bafa1732c6f58ec8f691cd114ed257
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 12, 2026.

Transparency log

Security for cmomy 1.2.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 cmomy-1.2.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 12, 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

1.2.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