【发布时间】:2020-07-25 23:18:50
【问题描述】:
我正在尝试通过阅读文档here 来了解数组分块的工作原理。
以下是我尝试重现示例的 Python 会话的输出。
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>
我希望a 的每个块(/块?)都具有(3, 3) 的形状,因为这是我在chunks 参数中指定的,也是文档中的示例所暗示的。
但是,当我读出第一个块时,它的形状是(3, 6)。
In [6]: a.blocks[0]
Out[6]: dask.array<blocks, shape=(3, 6), dtype=int64, chunksize=(3, 3), chunktype=numpy.ndarray>
而且,正如预期的那样,我只能读出两个块。当我读出第三个块时,会引发 IndexError。
In [7]: a.blocks[2]
...
IndexError: Index is not smaller than dimension 2 >= 2
我希望有四个 3x3 块,而不是两个 3x6 块。
关于数组分块在 dask 中的工作原理,我有什么不明白的地方?
【问题讨论】:
-
同意,这看起来很奇怪。也许github.com/dask/dask/blob/master/dask/array/core.py#L2357 发生了一些变化?我建议提交一个问题。在您上面概述的情况下,dask 构建了两个 (3,6) 数组,鉴于文档,这很奇怪
-
谢谢@joshreback