aerosandbox.numpy ================= .. py:module:: aerosandbox.numpy Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/aerosandbox/numpy/arithmetic_dyadic/index /autoapi/aerosandbox/numpy/arithmetic_monadic/index /autoapi/aerosandbox/numpy/array/index /autoapi/aerosandbox/numpy/calculus/index /autoapi/aerosandbox/numpy/conditionals/index /autoapi/aerosandbox/numpy/determine_type/index /autoapi/aerosandbox/numpy/finite_difference_operators/index /autoapi/aerosandbox/numpy/integrate/index /autoapi/aerosandbox/numpy/integrate_discrete/index /autoapi/aerosandbox/numpy/interpolate/index /autoapi/aerosandbox/numpy/linalg/index /autoapi/aerosandbox/numpy/linalg_top_level/index /autoapi/aerosandbox/numpy/logicals/index /autoapi/aerosandbox/numpy/rotations/index /autoapi/aerosandbox/numpy/spacing/index /autoapi/aerosandbox/numpy/surrogate_model_tools/index /autoapi/aerosandbox/numpy/trig/index Attributes ---------- .. autoapisummary:: aerosandbox.numpy._deg2rad aerosandbox.numpy._rad2deg Functions --------- .. autoapisummary:: aerosandbox.numpy.is_casadi_type aerosandbox.numpy.array aerosandbox.numpy.concatenate aerosandbox.numpy.stack aerosandbox.numpy.hstack aerosandbox.numpy.vstack aerosandbox.numpy.dstack aerosandbox.numpy.length aerosandbox.numpy.diag aerosandbox.numpy.roll aerosandbox.numpy.max aerosandbox.numpy.min aerosandbox.numpy.reshape aerosandbox.numpy.ravel aerosandbox.numpy.tile aerosandbox.numpy.zeros_like aerosandbox.numpy.ones_like aerosandbox.numpy.empty_like aerosandbox.numpy.full_like aerosandbox.numpy.assert_equal_shape aerosandbox.numpy.is_casadi_type aerosandbox.numpy.sum aerosandbox.numpy.mean aerosandbox.numpy.abs aerosandbox.numpy.prod aerosandbox.numpy.where aerosandbox.numpy.is_casadi_type aerosandbox.numpy._make_casadi_types_broadcastable aerosandbox.numpy.add aerosandbox.numpy.multiply aerosandbox.numpy.mod aerosandbox.numpy.centered_mod aerosandbox.numpy.is_casadi_type aerosandbox.numpy._centered_mod aerosandbox.numpy.array aerosandbox.numpy.concatenate aerosandbox.numpy.reshape aerosandbox.numpy.diff aerosandbox.numpy.gradient aerosandbox.numpy.trapz aerosandbox.numpy.is_casadi_type aerosandbox.numpy.where aerosandbox.numpy.maximum aerosandbox.numpy.minimum aerosandbox.numpy.array aerosandbox.numpy.length aerosandbox.numpy.finite_difference_coefficients aerosandbox.numpy.quad aerosandbox.numpy.solve_ivp aerosandbox.numpy.lotkavolterra_func aerosandbox.numpy.is_casadi_type aerosandbox.numpy.array aerosandbox.numpy.zeros_like aerosandbox.numpy.where aerosandbox.numpy.all aerosandbox.numpy.any aerosandbox.numpy.logical_or aerosandbox.numpy.interp aerosandbox.numpy.is_data_structured aerosandbox.numpy.interpn aerosandbox.numpy.is_casadi_type aerosandbox.numpy.dot aerosandbox.numpy.cross aerosandbox.numpy.transpose aerosandbox.numpy.is_casadi_type aerosandbox.numpy.clip aerosandbox.numpy.logical_and aerosandbox.numpy.logical_or aerosandbox.numpy.logical_not aerosandbox.numpy.all aerosandbox.numpy.any aerosandbox.numpy.array aerosandbox.numpy.rotation_matrix_2D aerosandbox.numpy.rotation_matrix_3D aerosandbox.numpy.rotation_matrix_from_euler_angles aerosandbox.numpy.is_valid_rotation_matrix aerosandbox.numpy.is_casadi_type aerosandbox.numpy.linspace aerosandbox.numpy.cosspace aerosandbox.numpy.sinspace aerosandbox.numpy.logspace aerosandbox.numpy.geomspace aerosandbox.numpy.softmax aerosandbox.numpy.softmin aerosandbox.numpy.softmax_scalefree aerosandbox.numpy.softmin_scalefree aerosandbox.numpy.softplus aerosandbox.numpy.sigmoid aerosandbox.numpy.swish aerosandbox.numpy.blend aerosandbox.numpy.degrees aerosandbox.numpy.radians aerosandbox.numpy.sind aerosandbox.numpy.cosd aerosandbox.numpy.tand aerosandbox.numpy.arcsind aerosandbox.numpy.arccosd aerosandbox.numpy.arctan2d Package Contents ---------------- .. py:function:: is_casadi_type(object, recursive = True) Returns a boolean of whether an object is a CasADi data type or not. If the recursive flag is True, iterates recursively, returning True if any subelement (at any depth) is a CasADi type. :param object: The object to evaluate. :param recursive: If the object is a list or tuple, recursively iterate through every subelement. If any of the :param subelements: :type subelements: at any depth Returns: A boolean if the object is (or contains, if recursive=True) a CasADi data type. .. py:function:: array(array_like, dtype=None) Initializes a new array. Creates a NumPy array if possible; if not, creates a CasADi array. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.array.html .. py:function:: concatenate(arrays, axis = 0) Join a sequence of arrays along an existing axis. Returns a NumPy array if possible; if not, returns a CasADi array. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.concatenate.html .. py:function:: stack(arrays, axis = 0) Join a sequence of arrays along a new axis. Returns a NumPy array if possible; if not, returns a CasADi array. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.stack.html .. py:function:: hstack(arrays) .. py:function:: vstack(arrays) .. py:function:: dstack(arrays) .. py:function:: length(array) Returns the length of an 1D-array-like object. An extension of len() with slightly different functionality. :param array: Returns: .. py:function:: diag(v, k=0) Extract a diagonal or construct a diagonal array. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.diag.html .. py:function:: roll(a, shift, axis = None) Roll array elements along a given axis. Elements that roll beyond the last position are re-introduced at the first. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.roll.html :param a: Input array. :type a: array_like :param shift: The number of places by which elements are shifted. If a tuple, then axis must be a tuple of the same size, and each of the given axes is shifted by the corresponding number. If an int while axis is a tuple of ints, then the same value is used for all given axes. :type shift: int or tuple of ints :param axis: Axis or axes along which elements are shifted. By default, the array is flattened before shifting, after which the original shape is restored. :type axis: int or tuple of ints, optional :returns: **res** -- Output array, with the same shape as a. :rtype: ndarray .. py:function:: max(a, axis=None) Return the maximum of an array or maximum along an axis. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.max.html .. py:function:: min(a, axis=None) Return the minimum of an array or minimum along an axis. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.min.html .. py:function:: reshape(a, newshape, order='C') Gives a new shape to an array without changing its data. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.reshape.html .. py:function:: ravel(a, order='C') Returns a contiguous flattened array. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.ravel.html .. py:function:: tile(A, reps) Construct an array by repeating A the number of times given by reps. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.tile.html .. py:function:: zeros_like(a, dtype=None, order='K', subok=True, shape=None) Return an array of zeros with the same shape and type as a given array. .. py:function:: ones_like(a, dtype=None, order='K', subok=True, shape=None) Return an array of ones with the same shape and type as a given array. .. py:function:: empty_like(prototype, dtype=None, order='K', subok=True, shape=None) Return a new array with the same shape and type as a given array. .. py:function:: full_like(a, fill_value, dtype=None, order='K', subok=True, shape=None) Return a full array with the same shape and type as a given array. .. py:function:: assert_equal_shape(arrays) Assert that all of the given arrays are the same shape. If this is not true, raise a ValueError. Args: arrays: The arrays to be evaluated. Can be provided as a: * List, in which case a generic ValueError is thrown * Dictionary consisting of name:array pairs for key:value, in which case the names are given in the ValueError. Returns: None. Throws an error if leng .. py:function:: is_casadi_type(object, recursive = True) Returns a boolean of whether an object is a CasADi data type or not. If the recursive flag is True, iterates recursively, returning True if any subelement (at any depth) is a CasADi type. :param object: The object to evaluate. :param recursive: If the object is a list or tuple, recursively iterate through every subelement. If any of the :param subelements: :type subelements: at any depth Returns: A boolean if the object is (or contains, if recursive=True) a CasADi data type. .. py:function:: sum(x, axis = None) Sum of array elements over a given axis. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.sum.html .. py:function:: mean(x, axis = None) Compute the arithmetic mean along the specified axis. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.mean.html .. py:function:: abs(x) .. py:function:: prod(x, axis = None) Return the product of array elements over a given axis. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.prod.html .. py:function:: where(condition, value_if_true, value_if_false) Return elements chosen from x or y depending on condition. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.where.html .. py:function:: is_casadi_type(object, recursive = True) Returns a boolean of whether an object is a CasADi data type or not. If the recursive flag is True, iterates recursively, returning True if any subelement (at any depth) is a CasADi type. :param object: The object to evaluate. :param recursive: If the object is a list or tuple, recursively iterate through every subelement. If any of the :param subelements: :type subelements: at any depth Returns: A boolean if the object is (or contains, if recursive=True) a CasADi data type. .. py:function:: _make_casadi_types_broadcastable(x1, x2) .. py:function:: add(x1, x2) .. py:function:: multiply(x1, x2) .. py:function:: mod(x1, x2) Return element-wise remainder of division. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.mod.html .. py:function:: centered_mod(x1, x2) Return element-wise remainder of division, centered on zero. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.mod.html .. py:function:: is_casadi_type(object, recursive = True) Returns a boolean of whether an object is a CasADi data type or not. If the recursive flag is True, iterates recursively, returning True if any subelement (at any depth) is a CasADi type. :param object: The object to evaluate. :param recursive: If the object is a list or tuple, recursively iterate through every subelement. If any of the :param subelements: :type subelements: at any depth Returns: A boolean if the object is (or contains, if recursive=True) a CasADi data type. .. py:function:: _centered_mod(x1, x2) Return element-wise remainder of division, centered on zero. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.mod.html .. py:function:: array(array_like, dtype=None) Initializes a new array. Creates a NumPy array if possible; if not, creates a CasADi array. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.array.html .. py:function:: concatenate(arrays, axis = 0) Join a sequence of arrays along an existing axis. Returns a NumPy array if possible; if not, returns a CasADi array. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.concatenate.html .. py:function:: reshape(a, newshape, order='C') Gives a new shape to an array without changing its data. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.reshape.html .. 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. .. py:function:: is_casadi_type(object, recursive = True) Returns a boolean of whether an object is a CasADi data type or not. If the recursive flag is True, iterates recursively, returning True if any subelement (at any depth) is a CasADi type. :param object: The object to evaluate. :param recursive: If the object is a list or tuple, recursively iterate through every subelement. If any of the :param subelements: :type subelements: at any depth Returns: A boolean if the object is (or contains, if recursive=True) a CasADi data type. .. py:function:: where(condition, value_if_true, value_if_false) Return elements chosen from x or y depending on condition. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.where.html .. py:function:: maximum(x1, x2) Element-wise maximum of two arrays. Note: not differentiable at the crossover point, will cause issues if you try to optimize across a crossover. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.maximum.html .. py:function:: minimum(x1, x2) Element-wise minimum of two arrays. Note: not differentiable at the crossover point, will cause issues if you try to optimize across a crossover. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.minimum.html .. py:function:: array(array_like, dtype=None) Initializes a new array. Creates a NumPy array if possible; if not, creates a CasADi array. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.array.html .. py:function:: length(array) Returns the length of an 1D-array-like object. An extension of len() with slightly different functionality. :param array: Returns: .. py:function:: finite_difference_coefficients(x, x0 = 0, derivative_degree = 1) Computes the weights (coefficients) in compact finite differece formulas for any order of derivative and to any order of accuracy on one-dimensional grids with arbitrary spacing. (Wording above is taken from the paper below, as are docstrings for parameters.) Modified from an implementation of: Fornberg, Bengt, "Generation of Finite Difference Formulas on Arbitrarily Spaced Grids". Oct. 1988. Mathematics of Computation, Volume 51, Number 184, pages 699-706. PDF: https://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf More detail: https://en.wikipedia.org/wiki/Finite_difference_coefficient :param derivative_degree: The degree of the derivative that you are interested in obtaining. (denoted "M" in the :param paper): :param x: The grid points (not necessarily uniform or in order) that you want to obtain weights for. You must :param provide at least as many grid points as the degree of the derivative that you're interested in: The order of accuracy of your derivative depends in part on the number of grid points that you provide. Specifically: order_of_accuracy = n_grid_points - derivative_degree (This is in general; can be higher in special cases.) For example, if you're evaluating a second derivative and you provide three grid points, you'll have a first-order-accurate answer. (x is denoted "alpha" in the paper) :param plus 1.: The order of accuracy of your derivative depends in part on the number of grid points that you provide. Specifically: order_of_accuracy = n_grid_points - derivative_degree (This is in general; can be higher in special cases.) For example, if you're evaluating a second derivative and you provide three grid points, you'll have a first-order-accurate answer. (x is denoted "alpha" in the paper) :param x0: The location that you are interested in obtaining a derivative at. This need not be on a grid point. Complexity is O(derivative_degree * len(x) ^ 2) Returns: A 1D ndarray corresponding to the coefficients that should be placed on each grid point. In other words, the approximate derivative at `x0` is the dot product of `coefficients` and the function values at each of the grid points `x`. .. py:function:: quad(func, a, b, full_output = False, variable_of_integration = None) .. py:function:: solve_ivp(fun, t_span, y0, method = 'RK45', t_eval = None, dense_output = False, events = None, vectorized = False, args = None, t_variable = None, y_variables = None, **options) .. py:function:: lotkavolterra_func(t, z) .. py:function:: is_casadi_type(object, recursive = True) Returns a boolean of whether an object is a CasADi data type or not. If the recursive flag is True, iterates recursively, returning True if any subelement (at any depth) is a CasADi type. :param object: The object to evaluate. :param recursive: If the object is a list or tuple, recursively iterate through every subelement. If any of the :param subelements: :type subelements: at any depth Returns: A boolean if the object is (or contains, if recursive=True) a CasADi data type. .. py:function:: array(array_like, dtype=None) Initializes a new array. Creates a NumPy array if possible; if not, creates a CasADi array. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.array.html .. py:function:: zeros_like(a, dtype=None, order='K', subok=True, shape=None) Return an array of zeros with the same shape and type as a given array. .. py:function:: where(condition, value_if_true, value_if_false) Return elements chosen from x or y depending on condition. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.where.html .. py:function:: all(a) Test whether all array elements along a given axis evaluate to True. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.all.html .. py:function:: any(a) Test whether any array element along a given axis evaluates to True. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.any.html .. py:function:: logical_or(x1, x2) Compute the truth value of x1 OR x2 element-wise. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.logical_or.html .. py:function:: interp(x, xp, fp, left=None, right=None, period=None) One-dimensional linear interpolation, analogous to numpy.interp(). Returns the one-dimensional piecewise linear interpolant to a function with given discrete data points (xp, fp), evaluated at x. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.interp.html Specific notes: xp is assumed to be sorted. .. py:function:: is_data_structured(x_data_coordinates, y_data_structured) Determines if the shapes of a given dataset are consistent with "structured" (i.e. gridded) data. For this to evaluate True, the inputs should be: x_data_coordinates: A tuple or list of 1D ndarrays that represent coordinates along each axis of a N-dimensional hypercube. y_data_structured: The values of some scalar defined on that N-dimensional hypercube, expressed as an N-dimesional array. In other words, y_data_structured is evaluated at `np.meshgrid(*x_data_coordinates, indexing="ij")`. Returns: Boolean of whether the above description is true. .. py:function:: interpn(points, values, xi, method = 'linear', bounds_error=True, fill_value=_onp.nan) Performs multidimensional interpolation on regular grids. Analogue to scipy.interpolate.interpn(). See syntax here: https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interpn.html :param points: The points defining the regular grid in n dimensions. Tuple of coordinates of each axis. Shapes (m1, :param ): :type ): mn, :param ...: :type ...: mn, :param : :type : mn, :param values: The data on the regular grid in n dimensions. Shape (m1, ..., mn) :param xi: The coordinates to sample the gridded data at. (..., ndim) :param method: The method of interpolation to perform. one of: * "bspline" (Note: differentiable and suitable for optimization - made of piecewise-cubics. For other applications, other interpolators may be faster. Not monotonicity-preserving - may overshoot.) * "linear" (Note: differentiable, but not suitable for use in optimization w/o subgradient treatment due to C1-discontinuity) * "nearest" (Note: NOT differentiable, don't use in optimization. Fast.) :param bounds_error: If True, when interpolated values are requested outside of the domain of the input data, :param a ValueError is raised. If False: :param then fill_value is used.: :param fill_value: If provided, the value to use for points outside of the interpolation domain. If None, :param values outside the domain are extrapolated.: Returns: Interpolated values at input coordinates. .. py:function:: is_casadi_type(object, recursive = True) Returns a boolean of whether an object is a CasADi data type or not. If the recursive flag is True, iterates recursively, returning True if any subelement (at any depth) is a CasADi type. :param object: The object to evaluate. :param recursive: If the object is a list or tuple, recursively iterate through every subelement. If any of the :param subelements: :type subelements: at any depth Returns: A boolean if the object is (or contains, if recursive=True) a CasADi data type. .. py:function:: dot(a, b, manual=False) Dot product of two arrays. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.dot.html .. py:function:: cross(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None, manual=False) Return the cross product of two (arrays of) vectors. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.cross.html .. py:function:: transpose(a, axes=None) Reverse or permute the axes of an array; returns the modified array. For an array a with two axes, transpose(a) gives the matrix transpose. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.transpose.html .. py:function:: is_casadi_type(object, recursive = True) Returns a boolean of whether an object is a CasADi data type or not. If the recursive flag is True, iterates recursively, returning True if any subelement (at any depth) is a CasADi type. :param object: The object to evaluate. :param recursive: If the object is a list or tuple, recursively iterate through every subelement. If any of the :param subelements: :type subelements: at any depth Returns: A boolean if the object is (or contains, if recursive=True) a CasADi data type. .. py:function:: clip(x, min, max) Clip a value to a range. :param x: Value to clip. :param min: Minimum value to clip to. :param max: Maximum value to clip to. Returns: .. py:function:: logical_and(x1, x2) Compute the truth value of x1 AND x2 element-wise. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.logical_and.html .. py:function:: logical_or(x1, x2) Compute the truth value of x1 OR x2 element-wise. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.logical_or.html .. py:function:: logical_not(x) Compute the truth value of NOT x element-wise. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.logical_not.html .. py:function:: all(a) Test whether all array elements along a given axis evaluate to True. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.all.html .. py:function:: any(a) Test whether any array element along a given axis evaluates to True. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.any.html .. py:function:: array(array_like, dtype=None) Initializes a new array. Creates a NumPy array if possible; if not, creates a CasADi array. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.array.html .. py:function:: rotation_matrix_2D(angle, as_array = True) Gives the 2D rotation matrix associated with a counterclockwise rotation about an angle. :param angle: Angle by which to rotate. Given in radians. :param as_array: Determines whether to return an array-like or just a simple list of lists. Returns: The 2D rotation matrix .. py:function:: rotation_matrix_3D(angle, axis, as_array = True, axis_already_normalized = False) Yields the rotation matrix that corresponds to a rotation by a specified amount about a given axis. An implementation of https://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle :param angle: The angle to rotate by. [radians] :param Direction of rotation corresponds to the right-hand rule.: :param Can be vectorized.: :param axis: The axis to rotate about. [ndarray] :param Can be vectorized; be sure axis[0] yields all the x-components: :param etc.: :param as_array: boolean, returns a 3x3 array-like if True, and a list-of-lists otherwise. If you are intending to use this function vectorized, it is recommended you flag this False. (Or test before proceeding.) :param axis_already_normalized: boolean, skips axis normalization for speed if you flag this true. :returns: The rotation matrix, with type according to the parameter `as_array`. .. py:function:: rotation_matrix_from_euler_angles(roll_angle = 0, pitch_angle = 0, yaw_angle = 0, as_array = True) Yields the rotation matrix that corresponds to a given Euler angle rotation. Note: This uses the standard (yaw, pitch, roll) Euler angle rotation, where: * First, a rotation about x is applied (roll) * Second, a rotation about y is applied (pitch) * Third, a rotation about z is applied (yaw) In other words: R = R_z(yaw) @ R_y(pitch) @ R_x(roll). Note: To use this, pre-multiply your vector to go from body axes to earth axes. Example: >>> vector_earth = rotation_matrix_from_euler_angles(np.pi / 4, np.pi / 4, np.pi / 4) @ vector_body See notes: http://planning.cs.uiuc.edu/node102.html :param roll_angle: The roll angle, which is a rotation about the x-axis. [radians] :param pitch_angle: The pitch angle, which is a rotation about the y-axis. [radians] :param yaw_angle: The yaw angle, which is a rotation about the z-axis. [radians] :param as_array: If True, returns a 3x3 array-like. If False, returns a list-of-lists. Returns: .. py:function:: is_valid_rotation_matrix(a, tol=1e-09) Returns a boolean of whether the given matrix satisfies the properties of a rotation matrix. Specifically, tests for: * Volume-preserving * Handedness of output reference frame * Orthogonality of output reference frame :param a: The array-like to be tested :param tol: A tolerance to use for truthiness; accounts for floating-point error. Returns: A boolean of whether the array-like is a valid rotation matrix. .. py:function:: is_casadi_type(object, recursive = True) Returns a boolean of whether an object is a CasADi data type or not. If the recursive flag is True, iterates recursively, returning True if any subelement (at any depth) is a CasADi type. :param object: The object to evaluate. :param recursive: If the object is a list or tuple, recursively iterate through every subelement. If any of the :param subelements: :type subelements: at any depth Returns: A boolean if the object is (or contains, if recursive=True) a CasADi data type. .. py:function:: linspace(start = 0.0, stop = 1.0, num = 50) Returns evenly spaced numbers over a specified interval. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.linspace.html .. py:function:: cosspace(start = 0.0, stop = 1.0, num = 50) Makes a cosine-spaced vector. Cosine spacing is useful because these correspond to Chebyshev nodes: https://en.wikipedia.org/wiki/Chebyshev_nodes To learn more about cosine spacing, see this: https://youtu.be/VSvsVgGbN7I :param start: Value to start at. :param end: Value to end at. :param num: Number of points in the vector. .. py:function:: sinspace(start = 0.0, stop = 1.0, num = 50, reverse_spacing = False) Makes a sine-spaced vector. By default, bunches points near the start. Sine spacing is exactly identical to half of a cosine-spaced distrubution, in terms of relative separations. To learn more about sine spacing and cosine spacing, see this: https://youtu.be/VSvsVgGbN7I :param start: Value to start at. :param end: Value to end at. :param num: Number of points in the vector. :param reverse_spacing: Does negative-sine spacing. In other words, if this is True, the points will be bunched near :param the `stop` rather than at the `start`.: Points are bunched up near the `start` of the interval by default. To reverse this, use the `reverse_spacing` parameter. .. py:function:: logspace(start = 0.0, stop = 1.0, num = 50) Return numbers spaced evenly on a log scale. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.logspace.html .. py:function:: geomspace(start = 1.0, stop = 10.0, num = 50) Return numbers spaced evenly on a log scale (a geometric progression). This is similar to logspace, but with endpoints specified directly. See syntax here: https://numpy.org/doc/stable/reference/generated/numpy.geomspace.html .. py:function:: softmax(*args, softness = None, hardness = None) An element-wise softmax between two or more arrays. Also referred to as the logsumexp() function. Useful for optimization because it's differentiable and preserves convexity! Great writeup by John D Cook here: https://www.johndcook.com/soft_maximum.pdf Notes: Can provide either `hardness` or `softness`, not both. These are the inverse of each other. If neither is provided, `hardness` is set to 1. :param \*args: Provide any number of arguments as values to take the softmax of. :param hardness: Hardness parameter. Higher values make this closer to max(x1, x2). :param softness: Softness parameter. (Inverse of hardness.) Lower values make this closer to max(x1, x2). - Setting `softness` is particularly useful, because it has the same units as each of the function's inputs. For example, if you're taking the softmax of two values that are lengths in units of meters, then `softness` is also in units of meters. In this case, `softness` has the rough meaning of "an amount of discrepancy between the input values that would be considered physically significant". :returns: Soft maximum of the supplied values. .. py:function:: softmin(*args, softness = None, hardness = None) An element-wise softmin between two or more arrays. Related to the logsumexp() function. Useful for optimization because it's differentiable and preserves convexity! Great writeup by John D Cook here: https://www.johndcook.com/soft_maximum.pdf Notes: Can provide either `hardness` or `softness`, not both. These are the inverse of each other. If neither is provided, `hardness` is set to 1. :param \*args: Provide any number of arguments as values to take the softmin of. :param hardness: Hardness parameter. Higher values make this closer to min(x1, x2). :param softness: Softness parameter. (Inverse of hardness.) Lower values make this closer to min(x1, x2). - Setting `softness` is particularly useful, because it has the same units as each of the function's inputs. For example, if you're taking the softmin of two values that are lengths in units of meters, then `softness` is also in units of meters. In this case, `softness` has the rough meaning of "an amount of discrepancy between the input values that would be considered physically significant". :returns: Soft minimum of the supplied values. .. py:function:: softmax_scalefree(*args, relative_softness = None, relative_hardness = None) .. py:function:: softmin_scalefree(*args, relative_softness = None, relative_hardness = None) .. py:function:: softplus(x, beta=1, threshold=40) A smooth approximation of the ReLU function, applied elementwise to an array `x`. Softplus(x) = 1/beta * log(1 + exp(beta * x)) Often used as an activation function in neural networks. :param x: The input :param beta: A parameter that controls the "softness" of the function. Higher values of beta make the function approach ReLU. :param threshold: Values above this threshold are approximated as linear. Returns: The value of the softplus function. .. py:function:: sigmoid(x, sigmoid_type = 'tanh', normalization_range = (0, 1)) A sigmoid function. From Wikipedia (https://en.wikipedia.org/wiki/Sigmoid_function): A sigmoid function is a mathematical function having a characteristic "S"-shaped curve or sigmoid curve. :param x: The input :param sigmoid_type: Type of sigmoid function to use [str]. Can be one of: * "tanh" or "logistic" (same thing) * "arctan" * "polynomial" :param normalization_type: Range in which to normalize the sigmoid, shorthanded here in the documentation as "N". This parameter is given as a two-element tuple (min, max). After normalization: >>> sigmoid(-Inf) == normalization_range[0] >>> sigmoid(Inf) == normalization_range[1] * In the special case of N = (0, 1): >>> sigmoid(-Inf) == 0 >>> sigmoid(Inf) == 1 >>> sigmoid(0) == 0.5 >>> d(sigmoid)/dx at x=0 == 0.5 * In the special case of N = (-1, 1): >>> sigmoid(-Inf) == -1 >>> sigmoid(Inf) == 1 >>> sigmoid(0) == 0 >>> d(sigmoid)/dx at x=0 == 1 Returns: The value of the sigmoid. .. py:function:: swish(x, beta = 1.0) A smooth approximation of the ReLU function, applied elementwise to an array `x`. Swish(x) = x / (1 + exp(-beta * x)) = x * logistic(x) = x * (0.5 + 0.5 * tanh(x/2)) Often used as an activation function in neural networks. :param x: The input :param beta: A parameter that controls the "softness" of the function. Higher values of beta make the function approach ReLU. Returns: The value of the swish function. .. py:function:: blend(switch, value_switch_high, value_switch_low) Smoothly blends between two values on the basis of some switch function. This function is similar in usage to numpy.where (documented here: https://numpy.org/doc/stable/reference/generated/numpy.where.html) , except that instead of using a boolean as to switch between the two values, a float is used to smoothly transition between the two in a differentiable manner. Before using this function, be sure to understand the difference between this and smoothmax(), and choose the correct one. :param switch: A value that acts as a "switch" between the two values [float]. If switch is -Inf, value_switch_low is returned. If switch is Inf, value_switch_high is returned. If switch is 0, the mean of value_switch_low and value_switch_high is returned. If switch is 1, the return value is roughly (0.88 * value_switch_high + 0.12 * value_switch_low). If switch is -1, the return value is roughly (0.88 * value_switch_low + 0.12 * value_switch_high). :param value_switch_high: Value to be returned when switch is high. Can be a float or an array. :param value_switch_low: Value to be returned when switch is low. Can be a float or an array. Returns: A value that is a blend between value_switch_low and value_switch_high, with the weighting dependent on the value of the 'switch' parameter. .. py:data:: _deg2rad .. py:data:: _rad2deg .. py:function:: degrees(x) Converts an input x from radians to degrees .. py:function:: radians(x) Converts an input x from degrees to radians .. py:function:: sind(x) Returns the sin of an angle x, given in degrees .. py:function:: cosd(x) Returns the cos of an angle x, given in degrees .. py:function:: tand(x) Returns the tangent of an angle x, given in degrees .. py:function:: arcsind(x) Returns the arcsin of an x, in degrees .. py:function:: arccosd(x) Returns the arccos of an x, in degrees .. py:function:: arctan2d(y, x) Returns the angle associated with arctan(y, x), in degrees