aerosandbox.numpy.calculus
Functions
diff(a[, n, axis, period]) | Calculate the n-th discrete difference along the given axis. |
gradient(f, *varargs[, axis, edge_order, n, period]) | Return the gradient of an N-dimensional array. |
trapz(x[, modify_endpoints]) | Computes each piece of the approximate integral of x via the trapezoidal method with unit spacing. |
Module Contents
aerosandbox.numpy.calculus.diff(a, n=1, axis=-1, period=None) : Calculate the n-th discrete difference along the given axis.
code
See syntax here: <https://numpy.org/doc/stable/reference/generated/numpy.diff.html>
Adds one new argument, period, which is the period of the data. If provided, the difference is taken assuming
the data “wraps around” at the period (i.e., modulo the period). For example:
>>> diff([345, 355, 5, 15], period=360)
>>> [10, 10, 10, 10]aerosandbox.numpy.calculus.gradient(f, *varargs, axis=None, edge_order=1, n=1, period=None) : Return the gradient of an N-dimensional array.
code
The gradient is computed using second order accurate central differences in the interior points and either first
or second order accurate one-sides (forward or backwards) differences at the boundaries. The returned gradient
hence has the same shape as the input array.
See syntax here: <https://numpy.org/doc/stable/reference/generated/numpy.gradient.html>
Parameters:
: - **f** – The array-like object to take the gradient of.
- **\*varargs** – The spacing between the points of f. If a scalar, the spacing is assumed to be uniform in all
dimensions. If an array, the array must have the same shape as f.
- **axis** – The axis along which the difference is taken. If None, the gradient is taken for all axes.
- **edge\_order** – The order of the error at the boundaries. 1 means first order, 2 means second order.
- **n** – This is a new argument (not in NumPy) that specifies the order of the derivative to take. 1 is the first
derivative (default), 2 is the second derivative. Doing np.gradient(f, n=2) results in less discretization
error than doing np.gradient(np.gradient(f)).
- **period** – The period of the data. If provided, the gradient is taken assuming the data “wraps around” at the period
(i.e., modulo the period). See aerosandbox.numpy.diff() for more information.
Returns: The gradient of f.aerosandbox.numpy.calculus.trapz(x, modify_endpoints=False) : Computes each piece of the approximate integral of x via the trapezoidal method with unit spacing. Can be viewed as the opposite of diff().
code
Parameters:
: **x** – The vector-like object (1D np.ndarray, cas.MX) to be integrated.
Returns: A vector of length N-1 with each piece corresponding to the mean value of the function on the interval
: starting at index i.