cf.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).

Parameters
shape: tuple of int, or any number of int

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. See dask.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 cf.chunksize function.

Returns
Data or None

The reshaped data, or None if the operation was in-place.

Examples

>>> d = cf.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]]]]