MCPcopy Create free account
hub / github.com/dask/dask / blocks

Method blocks

dask/array/core.py:2109–2146  ·  view source on GitHub ↗

An array-like interface to the blocks of an array. This returns a ``Blockview`` object that provides an array-like interface to the blocks of a dask array. Numpy-style indexing of a ``Blockview`` object returns a selection of blocks as a new dask array. You can ind

(self)

Source from the content-addressed store, hash-verified

2107
2108 @property
2109 def blocks(self):
2110 """An array-like interface to the blocks of an array.
2111
2112 This returns a ``Blockview`` object that provides an array-like interface
2113 to the blocks of a dask array. Numpy-style indexing of a ``Blockview`` object
2114 returns a selection of blocks as a new dask array.
2115
2116 You can index ``array.blocks`` like a numpy array of shape
2117 equal to the number of blocks in each dimension, (available as
2118 array.blocks.size). The dimensionality of the output array matches
2119 the dimension of this array, even if integer indices are passed.
2120 Slicing with ``np.newaxis`` or multiple lists is not supported.
2121
2122 Examples
2123 --------
2124 >>> import dask.array as da
2125 >>> x = da.arange(8, chunks=2)
2126 >>> x.blocks.shape # aliases x.numblocks
2127 (4,)
2128 >>> x.blocks[0].compute()
2129 array([0, 1])
2130 >>> x.blocks[:3].compute()
2131 array([0, 1, 2, 3, 4, 5])
2132 >>> x.blocks[::2].compute()
2133 array([0, 1, 4, 5])
2134 >>> x.blocks[[-1, 0]].compute()
2135 array([6, 7, 0, 1])
2136 >>> x.blocks.ravel() # doctest: +NORMALIZE_WHITESPACE
2137 [dask.array<blocks, shape=(2,), dtype=int64, chunksize=(2,), chunktype=numpy.ndarray>,
2138 dask.array<blocks, shape=(2,), dtype=int64, chunksize=(2,), chunktype=numpy.ndarray>,
2139 dask.array<blocks, shape=(2,), dtype=int64, chunksize=(2,), chunktype=numpy.ndarray>,
2140 dask.array<blocks, shape=(2,), dtype=int64, chunksize=(2,), chunktype=numpy.ndarray>]
2141
2142 Returns
2143 -------
2144 An instance of ``dask.array.Blockview``
2145 """
2146 return BlockView(self)
2147
2148 @property
2149 def partitions(self):

Callers

nothing calls this directly

Calls 1

BlockViewClass · 0.85

Tested by

no test coverage detected