1

I am trying to learn how array chunking works by reading the docs here.

Below is an output from a Python session where I try to reproduce the examples.

In [1]: import numpy as np

In [2]: npa = np.array([
   ...: [1, 2, 3, 4, 5, 6],
   ...: [7, 8, 9, 0, 1, 2],
   ...: [3, 4, 5, 6, 7, 8],
   ...: [9, 0, 1, 2, 3, 4],
   ...: [5, 6, 7, 8, 9, 0],
   ...: [1, 2, 3, 4, 5, 6]
   ...: ])

In [3]: import dask.array as da

In [4]: a = da.from_array(npa, chunks=3)

In [5]: a
Out[5]: dask.array<array, shape=(6, 6), dtype=int64, chunksize=(3, 3), chunktype=numpy.ndarray>

I would expect each chunk(/block?) of a to have shape (3, 3) since that is what I specified in the chunks parameter and what the example in the docs seems to suggest.

However, when I read out the first block, it has a shape of (3, 6).

In [6]: a.blocks[0]
Out[6]: dask.array<blocks, shape=(3, 6), dtype=int64, chunksize=(3, 3), chunktype=numpy.ndarray>

And, as expected given the shape, I can only read out two blocks. When I read out the third block an IndexError is raised.

In [7]: a.blocks[2]
...
IndexError: Index is not smaller than dimension 2 >= 2

I would expect there to be four 3x3 blocks, not two 3x6 blocks.

What am I not understanding about how array chunking works in dask?

2
  • Agreed, this does seem odd. Maybe something has changed in github.com/dask/dask/blob/master/dask/array/core.py#L2357 ? I'd recommend filing an issue. In the case you've outlined above dask builds two arrays of (3,6) which is strange given the docs Commented Jul 28, 2020 at 17:32
  • Thanks @joshreback Commented Aug 4, 2020 at 17:21

1 Answer 1

1

Answered here.

Your chunks/blocks are in two dimensions, so you can index them in two dimensions

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.