NumPy MinMax
numpy-minmax is a fast Python library designed to efficiently find both the minimum and maximum values within a NumPy array. It achieves significant speedups (roughly 2.3x faster than calling `numpy.amin` and `numpy.amax` separately) by leveraging C implementations and SIMD instructions (AVX/AVX512). The library is actively maintained with frequent releases, with version 0.5.0 being the latest stable release as of June 2025.
Warnings
- gotcha Performance benefits of `numpy-minmax` are primarily realized for `float32` and `int16` arrays that are C-contiguous, F-contiguous, or 1D strided. For other data types or strided arrays with `ndim >= 2`, the function falls back to `numpy.amin` and `numpy.amax`, negating any performance gain.
- breaking The library has a history of adjusting Python version support with minor releases. For example, version 0.5.0 added Python 3.13 support, while the upcoming 0.6.0 will remove Python 3.9 support. Users should consult the `CHANGELOG.md` on GitHub or PyPI for supported Python versions to ensure compatibility.
Install
-
pip install numpy-minmax
Imports
- minmax
from numpy_minmax import minmax
Quickstart
import numpy as np
from numpy_minmax import minmax
arr = np.arange(1337, dtype=np.float32)
min_val, max_val = minmax(arr)
print(f"Min value: {min_val}")
print(f"Max value: {max_val}")
# Expected output: Min value: 0.0, Max value: 1336.0