numpy_function#
- clipped_cumsum(a: ndarray, xmin=-inf, xmax=inf)[source]#
Compute a cumulative sum along the first axis with clipping.
This function computes the cumulative sum of a along the first axis (rows). After adding each row, intermediate cumulative values are clipped to the interval [xmin, xmax]. The clipping is applied elementwise across columns for 2-D input. The function preserves the input shape:
If a is 1-D, it is treated as a single column and the result is a
1-D array of the same shape. - If a is 2-D (shape (n_steps, n_series)), the cumulative sum is computed independently for each column and the result has the same shape as a.
- Parameters:
a (np.ndarray) – Input array. Expected shape is (n_steps,) or (n_steps, n_series). The cumulative sum is performed along axis 0.
xmin (float, optional) – Minimum allowed cumulative value (inclusive). Defaults to -inf.
xmax (float, optional) – Maximum allowed cumulative value (inclusive). Defaults to +inf.
- Returns:
Array of the same shape as a containing the clipped cumulative sums.
- Return type:
np.ndarray
Notes
The function uses an internal accumulator initialized to zeros with
length equal to the number of columns (1 for 1-D input). - Clipping is applied elementwise after each accumulation step using np.minimum and np.maximum so values stay within [xmin, xmax].
Examples
>>> import numpy as np >>> a = np.array([1, 2, -1, 5]) >>> clipped_cumsum(a, xmin=0, xmax=5) array([1, 3, 2, 5])
>>> b = np.array([[1, 0], [2, 3], [4, -2]]) >>> clipped_cumsum(b, xmin=-1, xmax=4) array([[ 1, 0], [ 3, 3], [ 4, 1]])
- error_within_boundaries(x: array, low: array, high: array) array[source]#
Calculate the error of values within specified boundaries.
- Parameters:
x (np.array) – The array of values.
low (np.array) – The lower boundary array.
high (np.array) – The upper boundary array.
- Returns:
The array of errors.
- Return type:
np.array
- relative_error_within_boundaries(x: array, low: array, high: array) array[source]#
Calculate the relative error of values within specified boundaries.
- Parameters:
x (np.array) – The array of values.
low (np.array) – The lower boundary array.
high (np.array) – The upper boundary array.
- Returns:
The array of relative errors.
- Return type:
np.array