API REFERENCE

rollit.normalize: NumPy Rolling Normalization

The rollit.normalize() function scales the last element of each sliding window to a range of [0, 1] relative to the local minimum and maximum values within that window.

rollit.normalize(arr, window, min_periods=None)

Formula

For each window frame, the final value is mapped relative to the window bounds:

Normalized =
xlast - minmax - min

Where xlast is the last element in the sliding window, and min/max represent the boundaries of that window. If all elements in the window are identical (resulting in max = min), the function returns NaN to avoid division by zero.

Parameters

arr (np.ndarray)

The input flat 1D NumPy array containing numeric entries.

window (int)

The size of the sliding window. Must be a positive integer >= 2.

min_periods (int | None, optional)

Minimum number of valid observations required in the window. Allows calculating normalization with partial missing values.

Use Case in Machine Learning: When feeding live time-series data into neural networks or regression models, data scaling must be localized to avoid drift. rollit.normalize() is perfect for running real-time, window-by-window min-max scaling to standard inputs without leakages.

Usage Example

import numpy as np
import rollit

# Input array of varying ranges
data = np.array([100.0, 102.0, 101.0, 105.0, 110.0, 95.0, 100.0])

# Compute rolling Min-Max normalization (window size = 3)
# Scales last element of each window to [0, 1]
normalized = rollit.normalize(data, window=3)

print("Original data:", data)
print("Normalized values:", normalized)
# Output: [ 0.5, 0.8, 1.0, 0.0, 0.33 ]
Need custom functions?Go to rollit.apply() API