make_data_same¶
- make_data_same(data_fix: Any | Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], shape: tuple | list, stack_ax: int = 0, pad_ax: int = -1, make_stacks_same: bool = True, rng: Generator = None) Any | Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str][source][source]¶
Force the last dimension of data_fix to match the last dimension of shape.
Takes the two arrays and checks if the last dimension of data_fix is smaller than the last dimension of shape. If there’s more than two dimensions, it will rearrange the data to match the shape. If there’s only two dimensions, it will repeat the signal to match the shape of data_like. If the last dimension of data_fix is larger than the last dimension of shape, it will return a subset of data_fix.
- Parameters:
- Returns:
data_fix – The reshaped data.
- Return type:
ArrayLike
Examples
>>> np.random.seed(0) >>> data_fix = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]) >>> make_data_same(data_fix, (2, 8)) array([[ 1, 2, 3, 4, 5, 4, 3, 2], [ 6, 7, 8, 9, 10, 9, 8, 7]]) >>> (newarr := make_data_same(data_fix, (2, 2), make_stacks_same=False)) array([[1, 2], [3, 4], [6, 7], [8, 9]]) >>> make_data_same(newarr, (3, 2), stack_ax=1, pad_ax=0) array([[1, 2], [3, 4], [6, 7]]) >>> import cupy as cp >>> make_data_same(cp.asarray(data_fix), (2, 2), ... make_stacks_same=False) array([[1, 2], [3, 4], [6, 7], [8, 9]])