MCPcopy Index your code
hub / github.com/dask/dask / BlockView

Class BlockView

dask/array/core.py:6172–6271  ·  view source on GitHub ↗

An array-like interface to the blocks of an array. ``BlockView`` provides an array-like interface to the blocks of a dask array. Numpy-style indexing of a ``BlockView`` returns a selection of blocks as a new dask array. You can index ``BlockView`` like a numpy array of shape

Source from the content-addressed store, hash-verified

6170
6171
6172class BlockView:
6173 """An array-like interface to the blocks of an array.
6174
6175 ``BlockView`` provides an array-like interface
6176 to the blocks of a dask array. Numpy-style indexing of a
6177 ``BlockView`` returns a selection of blocks as a new dask array.
6178
6179 You can index ``BlockView`` like a numpy array of shape
6180 equal to the number of blocks in each dimension, (available as
6181 array.blocks.size). The dimensionality of the output array matches
6182 the dimension of this array, even if integer indices are passed.
6183 Slicing with ``np.newaxis`` or multiple lists is not supported.
6184
6185 Examples
6186 --------
6187 >>> import dask.array as da
6188 >>> from dask.array.core import BlockView
6189 >>> x = da.arange(8, chunks=2)
6190 >>> bv = BlockView(x)
6191 >>> bv.shape # aliases x.numblocks
6192 (4,)
6193 >>> bv.size
6194 4
6195 >>> bv[0].compute()
6196 array([0, 1])
6197 >>> bv[:3].compute()
6198 array([0, 1, 2, 3, 4, 5])
6199 >>> bv[::2].compute()
6200 array([0, 1, 4, 5])
6201 >>> bv[[-1, 0]].compute()
6202 array([6, 7, 0, 1])
6203 >>> bv.ravel() # doctest: +NORMALIZE_WHITESPACE
6204 [dask.array<blocks, shape=(2,), dtype=int64, chunksize=(2,), chunktype=numpy.ndarray>,
6205 dask.array<blocks, shape=(2,), dtype=int64, chunksize=(2,), chunktype=numpy.ndarray>,
6206 dask.array<blocks, shape=(2,), dtype=int64, chunksize=(2,), chunktype=numpy.ndarray>,
6207 dask.array<blocks, shape=(2,), dtype=int64, chunksize=(2,), chunktype=numpy.ndarray>]
6208
6209 Returns
6210 -------
6211 An instance of ``da.array.Blockview``
6212 """
6213
6214 def __init__(self, array: Array):
6215 self._array = array
6216
6217 def __getitem__(self, index: Any) -> Array:
6218 from dask.array.slicing import normalize_index
6219
6220 if not isinstance(index, tuple):
6221 index = (index,)
6222 if sum(isinstance(ind, (np.ndarray, list)) for ind in index) > 1:
6223 raise ValueError("Can only slice with a single list")
6224 if any(ind is None for ind in index):
6225 raise ValueError("Slicing with np.newaxis or None is not supported")
6226 index = normalize_index(index, self._array.numblocks)
6227 index = tuple(
6228 slice(k, k + 1) if isinstance(k, Number) else k # type: ignore[operator]
6229 for k in index

Callers 2

test_blockviewFunction · 0.90
blocksMethod · 0.85

Calls

no outgoing calls

Tested by 1

test_blockviewFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…