Convert blocks in dask array x for new chunks. Parameters ---------- x: dask array Array to be rechunked. chunks: int, tuple, dict or str, optional The new block dimensions to create. -1 indicates the full size of the corresponding dimension. Default is
(
x,
chunks="auto",
threshold=None,
block_size_limit=None,
balance=False,
method=None,
)
| 931 | |
| 932 | |
| 933 | def rechunk( |
| 934 | x, |
| 935 | chunks="auto", |
| 936 | threshold=None, |
| 937 | block_size_limit=None, |
| 938 | balance=False, |
| 939 | method=None, |
| 940 | ): |
| 941 | """ |
| 942 | Convert blocks in dask array x for new chunks. |
| 943 | |
| 944 | Parameters |
| 945 | ---------- |
| 946 | x: dask array |
| 947 | Array to be rechunked. |
| 948 | chunks: int, tuple, dict or str, optional |
| 949 | The new block dimensions to create. -1 indicates the full size of the |
| 950 | corresponding dimension. Default is "auto" which automatically |
| 951 | determines chunk sizes. |
| 952 | threshold: int, optional |
| 953 | The graph growth factor under which we don't bother introducing an |
| 954 | intermediate step. |
| 955 | block_size_limit: int, optional |
| 956 | The maximum block size (in bytes) we want to produce |
| 957 | Defaults to the configuration value ``array.chunk-size`` |
| 958 | balance : bool, default False |
| 959 | If True, try to make each chunk to be the same size. |
| 960 | |
| 961 | This means ``balance=True`` will remove any small leftover chunks, so |
| 962 | using ``x.rechunk(chunks=len(x) // N, balance=True)`` |
| 963 | will almost certainly result in ``N`` chunks. |
| 964 | method: {'tasks', 'p2p'}, optional. |
| 965 | Rechunking method to use. |
| 966 | |
| 967 | |
| 968 | Examples |
| 969 | -------- |
| 970 | >>> import dask.array as da |
| 971 | >>> x = da.ones((1000, 1000), chunks=(100, 100)) |
| 972 | |
| 973 | Specify uniform chunk sizes with a tuple |
| 974 | |
| 975 | >>> y = x.rechunk((1000, 10)) |
| 976 | |
| 977 | Or chunk only specific dimensions with a dictionary |
| 978 | |
| 979 | >>> y = x.rechunk({0: 1000}) |
| 980 | |
| 981 | Use the value ``-1`` to specify that you want a single chunk along a |
| 982 | dimension or the value ``"auto"`` to specify that dask can freely rechunk a |
| 983 | dimension to attain blocks of a uniform block size |
| 984 | |
| 985 | >>> y = x.rechunk({0: -1, 1: 'auto'}, block_size_limit=1e8) |
| 986 | |
| 987 | If a chunk size does not divide the dimension then rechunk will leave any |
| 988 | unevenness to the last chunk. |
| 989 | |
| 990 | >>> x.rechunk(chunks=(400, -1)).chunks |
no test coverage detected