rand_offset_reshape

rand_offset_reshape(data_fix: Any | Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], shape: tuple, stack_ax: int, pad_ax: int, rng: Generator | int = None) Any | Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str][source][source]

Take subsets of data_fix and stack them together on the stack dimension

This function takes the data and reshapes it to match the shape by taking subsets of data_fix and stacking them together on the stack dimension, randomly offsetting the start of the first subset. It is assumed that the padding axis ‘pad_ax’ is larger in data_fix.shape than in shape.

Parameters:
  • data_fix (ArrayLike) – The data to reshape.

  • shape (list | tuple) – The shape of data to match.

  • stack_ax (int) – The axis along which to stack the subsets.

  • pad_ax (int) – The axis along which to slice the subsets.

  • rng (np.random.Generator | int, optional) – The random number generator to use. If None, a default random number generator will be used.

Returns:

data_fix – The reshaped data.

Return type:

ArrayLike

Examples

>>> data_fix = np.arange(50).reshape((5, 10))
>>> data_fix
array([[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
       [20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
       [30, 31, 32, 33, 34, 35, 36, 37, 38, 39],
       [40, 41, 42, 43, 44, 45, 46, 47, 48, 49]])
>>> rand_offset_reshape(data_fix, (2, 4), 0, 1, 0)
array([[ 1,  2,  3,  4],
       [ 5,  6,  7,  8],
       [11, 12, 13, 14],
       [15, 16, 17, 18],
       [21, 22, 23, 24],
       [25, 26, 27, 28],
       [31, 32, 33, 34],
       [35, 36, 37, 38],
       [41, 42, 43, 44],
       [45, 46, 47, 48]])
>>> rand_offset_reshape(data_fix, (2, 4), 1, 0, 0)
array([[ 0, 20,  1, 21,  2, 22,  3, 23,  4, 24,  5, 25,  6, 26,  7, 27,
         8, 28,  9, 29],
       [10, 30, 11, 31, 12, 32, 13, 33, 14, 34, 15, 35, 16, 36, 17, 37,
        18, 38, 19, 39]])