cfdm.Data.reshape¶
-
Data.
reshape
(*shape, merge_chunks=True, limit=None, inplace=False)[source]¶ Change the shape of the data without changing its values.
It assumes that the array is stored in row-major order, and only allows for reshapings that collapse or merge dimensions like
(1, 2, 3, 4) -> (1, 6, 4)
or(64,) -> (4, 4, 4)
.New in version (cfdm): 1.11.2.0
- Parameters
- shape:
tuple
ofint
, or any number ofint
The new shape for the data, which should be compatible with the original shape. If an integer, then the result will be a 1-d array of that length. One shape dimension can be -1, in which case the value is inferred from the length of the array and remaining dimensions.
- merge_chunks:
bool
When True (the default) merge chunks using the logic in
dask.array.rechunk
when communication is necessary given the input array chunking and the output shape. When False, the input array will be rechunked to a chunksize of 1, which can create very many tasks. Seedask.array.reshape
for details.- limit: int, optional
The maximum block size to target in bytes. If no limit is provided, it defaults to a size in bytes defined by the
cfdm.chunksize
function.- inplace:
bool
, optional If True then do the operation in-place and return
None
.
- shape:
- Returns
Examples
>>> d = cfdm.Data(np.arange(12)) >>> print(d.array) [ 0 1 2 3 4 5 6 7 8 9 10 11] >>> print(d.reshape(3, 4).array) [[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]] >>> print(d.reshape((4, 3)).array) [[ 0 1 2] [ 3 4 5] [ 6 7 8] [ 9 10 11]] >>> print(d.reshape(-1, 6).array) [[ 0 1 2 3 4 5] [ 6 7 8 9 10 11]] >>> print(d.reshape(1, 1, 2, 6).array) [[[[ 0 1 2 3 4 5] [ 6 7 8 9 10 11]]]] >>> print(d.reshape(1, 1, -1).array) [[[[ 0 1 2 3 4 5 6 7 8 9 10 11]]]]