aerosandbox.numpy.calculus ========================== .. py:module:: aerosandbox.numpy.calculus Functions --------- .. autoapisummary:: aerosandbox.numpy.calculus.diff aerosandbox.numpy.calculus.gradient aerosandbox.numpy.calculus.trapz Module Contents --------------- .. py:function:: diff(a, n=1, axis=-1, period=None) Calculate the n-th discrete difference along the given axis. 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] .. py:function:: gradient(f, *varargs, axis=None, edge_order=1, n=1, period=None) Return the gradient of an N-dimensional array. 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 :param f: The array-like object to take the gradient of. :param \*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. :param axis: The axis along which the difference is taken. If None, the gradient is taken for all axes. :param edge_order: The order of the error at the boundaries. 1 means first order, 2 means second order. :param 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))`. :param 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. .. py:function:: 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(). :param 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.