当我尝试像对Numpy数组进行切片一样对Zarr数组进行切片时,为什么会出现这个错误?

kokeuurv  于 2022-11-10  发布在  其他
关注(0)|答案(1)|浏览(93)

我正在使用以下代码从磁盘分割一个Zarr数组:

import zarr as zr

db = zr.open('/content/drive/My Drive/Share/Daily Data/Database/dbz.zarr', mode='r')
data = db[db[:,0]==20171003]

以下是错误:

IndexError                                Traceback (most recent call last)
<ipython-input-16-4ae364a8c3b1> in <module>()
      1 dbz_ranked = zr.open('/content/drive/My Drive/Share/Daily Data/Database/dbz_ranked.zarr', mode='w', shape=(8245164, 345),chunks=(100000, 345), dtype='float64')
----> 2   data = db[db[:,0]==20171003]

3 frames
/usr/local/lib/python3.6/dist-packages/zarr/indexing.py in __init__(self, selection, array)
    280                 raise IndexError('unsupported selection item for basic indexing; '
    281                                  'expected integer or slice, got {!r}'
--> 282                                  .format(type(dim_sel)))
    283 
    284             dim_indexers.append(dim_indexer)

IndexError: unsupported selection item for basic indexing; expected integer or slice, got <class 'numpy.ndarray'>

我不知道为什么这不起作用,我以为Zarr应该像块块数组一样切片?

qnzebej0

qnzebej01#

我发现以下页面很有帮助:https://zarr.readthedocs.io/en/stable/api/core.html
总而言之,使用zarr_array.oindex([])允许经典的索引/切片。

相关问题