reshape_as_blocks¶
- astropy.nddata.reshape_as_blocks(data, block_size)[source]¶
Reshape a data array into blocks.
This is useful to efficiently apply functions on block subsets of the data instead of using loops. The reshaped array is a view of the input data array.
New in version 4.1.
- Parameters:
- data
ndarray The input data array.
- block_size
intor array_like (int) The integer block size along each axis. If
block_sizeis a scalar anddatahas more than one dimension, thenblock_sizewill be used for for every axis. Each dimension ofblock_sizemust divide evenly into the corresponding dimension ofdata.
- data
- Returns:
- output
ndarray The reshaped array as a view of the input
dataarray.
- output
Examples
>>> import numpy as np >>> from astropy.nddata import reshape_as_blocks >>> data = np.arange(16).reshape(4, 4) >>> data array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15]]) >>> reshape_as_blocks(data, (2, 2)) array([[[[ 0, 1], [ 4, 5]], [[ 2, 3], [ 6, 7]]], [[[ 8, 9], [12, 13]], [[10, 11], [14, 15]]]])