flex_reshape

Contents

flex_reshape#

tollan.utils.np.flex_reshape(arr: npt.NDArray, shape: Sequence[int], trim_option: Literal['end', 'start'] = 'end') npt.NDArray[source]#

Reshape an array, trimming elements if needed.

Parameters:
  • arr (ndarray) – Array to reshape.

  • shape (sequence of int) – New shape (may include one -1 for auto size).

  • trim_option ({'end', 'start'}, optional) – Trim from end or start if needed (default: ‘end’).

Returns:

Reshaped array.

Return type:

ndarray

Examples

>>> import numpy as np
>>> arr = np.arange(10)
>>> flex_reshape(arr, (2, 4))
array([[0, 1, 2, 3],
       [4, 5, 6, 7]])