MCPcopy
hub / github.com/dask/dask / __getitem__

Method __getitem__

dask/array/core.py:6217–6245  ·  view source on GitHub ↗
(self, index: Any)

Source from the content-addressed store, hash-verified

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
6230 )
6231
6232 name = "blocks-" + tokenize(self._array, index)
6233
6234 new_keys = self._array._key_array[index]
6235
6236 chunks = tuple(
6237 tuple(np.array(c)[i].tolist()) for c, i in zip(self._array.chunks, index)
6238 )
6239
6240 keys = product(*(range(len(c)) for c in chunks))
6241
6242 graph: Graph = {(name,) + key: tuple(new_keys[key].tolist()) for key in keys}
6243
6244 hlg = HighLevelGraph.from_collections(name, graph, dependencies=[self._array])
6245 return Array(hlg, name, chunks, meta=self._array)
6246
6247 def __eq__(self, other: object) -> bool:
6248 if isinstance(other, BlockView):

Callers

nothing calls this directly

Calls 6

sumFunction · 0.90
anyFunction · 0.90
normalize_indexFunction · 0.90
from_collectionsMethod · 0.80
ArrayClass · 0.70
tokenizeFunction · 0.50

Tested by

no test coverage detected