Skip to content

santarsierilorenzo/arrayflux

Repository files navigation

arrayflux

Python NumPy SciPy PyTest Subclass

Tired of not having rolling method on NumPy arrays I created arrayflux!


arrayflux is a lightweight, production-ready Python library that extends numpy.ndarray with efficient rolling-window operations, fully compatible with NumPy semantics, slicing, memory model, and ufunc system.

📦 Installation (PyPI Package)

pip install arrayflux

⚙️ Usage Example

from arrayflux import arrayflux

x = arrayflux([1, 2, 3, 4, 5, 6])
r = x.rolling(3)

print(r.mean())  # [nan nan 2. 3. 4. 5.]

💡 How it works

I was tired of not having a native rolling method on NumPy arrays, and since I didn’t want to use pandas for this specific need, I created arrayflux. The idea is simple: extend NumPy’s ndarray with a clean and intuitive .rolling() API while keeping full NumPy compatibility and behavior.

Under the hood, the user interacts only with a small public API exposed in api.py, which provides a function that accepts any iterable and returns an ArrayFlux object. The ArrayFlux class itself lives in core.py, where the new method converts the input iterable into a NumPy array and applies .view(ArrayFlux) so that the object keeps all ndarray properties. The same class implements the .rolling(window) method, which performs a lazy import of the Rolling class and instantiates it using the desired window size. The Rolling class, defined in rolling.py, builds the actual rolling-window representation using numpy.lib.stride_tricks.sliding_window_view. All rolling operations (mean, std, var, skew, kurtosis, covariance, correlation, etc.) operate directly on this windowed view, and results are padded with leading NaN values to preserve the original array length.

The goal of arrayflux is to provide a lightweight, NumPy-native rolling system that is easy to use, easy to integrate, and fast to compute, without relying on heavier dependencies or abandoning the ndarray model.

🪪 License

MIT © 2025 — Developed with ❤️ by Lorenzo Santarsieri

About

Tired of not having rolling method on NumPy arrays I created arrayflux.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors