scijit.integrate.cumulative_trapezoid¶
- scijit.integrate.cumulative_trapezoid(y, x=None, dx=1.0, axis=-1, initial=None)¶
Running integral by the composite trapezoid rule.
Takes NO callback of either style: it integrates samples, not a function.
- Parameters:
- yarray_like
Samples to integrate, of any rank. An integer or boolean array is promoted to float64 and a complex one stays complex. Copied to a contiguous buffer, so strided views are safe.
- xarray_like or None, optional
Sample positions, which may be non-uniform. Either 1-D along
axis, or ofy’s rank.None(the default) means equal spacingdx.- dxfloat, optional
Spacing used when
xis None. Default 1.0.- axisint, optional
Axis to integrate along. Default -1, the last axis.
- initialfloat or None, optional
Value prepended to the result along
axis, which then has the same length there asy, and added to every element.None(the default) returns then - 1running integrals. Inside@njitthe choice betweenNoneand a float fixes the length, so it must not be a variable that is sometimes one and sometimes the other.
- Returns:
- resndarray
Running integral, of
y’s rank. Alongaxisits length isn - 1, the integral evaluated at the samples after the first, ornwhen a leading value is prepended.
- Raises:
- IndexError
axisoutsidey’s rank, from indexingy.shape.- ValueError
No samples along
axis;xneither 1-D nor ofy’s rank;xandyof different lengths alongaxis;initialneitherNonenor a scalar.
See also
scipy.integrate.cumulative_trapezoidThe scipy routine this mirrors.
Notes
A non-zero
initialis accepted, prepended and added to every element.scipy.integrate.cumulative_trapezoidraisesValueError: `initial` must be `None` or `0`.and accepts a non-zeroinitialonly oncumulative_simpson.Pure
@njit, no state, so prange-safe.Examples
>>> import numpy as np >>> from numba import njit >>> import scijit.integrate as si >>> x = np.linspace(0.0, np.pi, 65) >>> @njit ... def run(x): ... return si.cumulative_trapezoid(np.sin(x), x, 1.0, -1, 0.0)[-1] >>> run(x) 1.9995983886400375
A 2-D
y, integrated down the rows:>>> si.cumulative_trapezoid(np.arange(6.0).reshape(2, 3), None, 1.0, 0) array([[1.5, 2.5, 3.5]])