rm_lite.utils.arrays ==================== .. py:module:: rm_lite.utils.arrays .. autoapi-nested-parse:: Array utils Attributes ---------- .. autoapisummary:: rm_lite.utils.arrays.DType rm_lite.utils.arrays.TQDM_OUT Functions --------- .. autoapisummary:: rm_lite.utils.arrays.arange rm_lite.utils.arrays.nd_to_two_d rm_lite.utils.arrays.two_d_to_nd Module Contents --------------- .. py:function:: arange(start: float | int, stop: float | int, step: float | int, rtol: float = 1e-05, atol: float = 1e-08, include_start: bool = True, include_stop: bool = False, **kwargs) -> numpy.typing.NDArray[numpy.float64] Combines numpy.arange and numpy.isclose to mimic open, half-open and closed intervals. Avoids also floating point rounding errors as with >>> np.arange(1, 1.3, 0.1) array([1., 1.1, 1.2, 1.3]) :param start: Start of the interval. :type start: float | int :param stop: End of the interval. :type stop: float | int :param step: Spacing between values. :type step: float | int :param rtol: if last element of array is within this relative tolerance to stop and include[0]==False, it is skipped. Defaults to 1e-05. :type rtol: float, optional :param atol: if last element of array is within this relative tolerance to stop and include[1]==False, it is skipped. Defaults to 1e-08. :type atol: float, optional :param include_start: if first element is included in the returned array. Defaults to True. :type include_start: bool, optional :param include_stop: if last elements are included in the returned array if stop equals last element. Defaults to False. :type include_stop: bool, optional :param kwargs: passed to np.arange :returns: as np.arange but eventually with first and last element stripped/added :rtype: _type_ .. py:function:: nd_to_two_d(arr: numpy.typing.NDArray[DType]) -> numpy.typing.NDArray[DType] Convert an array to 2D. - If arr is 1D, it will be reshaped as a column vector (shape: (N, 1)). - If arr is already 2D, it is returned as is. - If arr has more than 2 dimensions, the first axis is kept intact and all remaining axes are flattened. For example, an array with shape (a, b, c, d) will become shape (a, b*c*d). :param arr: N-dimensional array. :type arr: NDArray[Any] :returns: 2D array. :rtype: NDArray[Any] .. py:function:: two_d_to_nd(arr2d: numpy.typing.NDArray[DType], original_shape: tuple[int, Ellipsis]) -> numpy.typing.NDArray[DType] Reverse the to_2d operation. :param arr2d: the 2D array (result from to_2d). :type arr2d: array-like :param original_shape: the shape of the original array before flattening. :type original_shape: tuple :returns: The array reshaped back to its original shape. The function assumes: - For an original 1D array, original_shape is (N,). In this case, arr2d is of shape (N, 1) and will be flattened back to (N,). - For an original 2D array, original_shape is (M, N) and arr2d is already (M, N). - For an original N_D array (N_D > 2) with shape (a, b, c, ...), arr2d is assumed to have shape (a, b*c*...) and will be reshaped back to (a, b, c, ...). .. py:data:: DType .. py:data:: TQDM_OUT