blosc2.NDArray.__getitem__#
- NDArray.__getitem__(key: int | slice | Sequence[slice | int] | np.ndarray[np.bool_] | blosc2.LazyExpr | str) np.ndarray | blosc2.LazyExpr #
Retrieve a (multidimensional) slice as specified by the key.
- Parameters:
key¶ (int, slice, sequence of (slices, int), array of bools, LazyExpr or str) – The slice(s) to be retrieved. Note that step parameter is not yet honored in slices. If a LazyExpr is provided, the expression is expected to be of boolean type, and the result will be another LazyExpr returning the values of this array where the expression is True. When key is a (nd-)array of bools, the result will be the values of
self
where the bool values are True (similar to NumPy). If key is a 1-dim sequence of integers, the result will be the values of this array at the specified indices. N-dim indices are not yet supported. If the key is a string, and it is a field name of self, a NDField accessor will be returned; if not, it will be attempted to convert to a LazyExpr, and will search for its operands in the fields ofself
.- Returns:
out – The requested data as a NumPy array or a LazyExpr.
- Return type:
np.ndarray | blosc2.LazyExpr
Examples
>>> import blosc2 >>> shape = [25, 10] >>> # Create an array >>> a = blosc2.full(shape, 3.3333) >>> # Get slice as a NumPy array >>> a[:5, :5] array([[3.3333, 3.3333, 3.3333, 3.3333, 3.3333], [3.3333, 3.3333, 3.3333, 3.3333, 3.3333], [3.3333, 3.3333, 3.3333, 3.3333, 3.3333], [3.3333, 3.3333, 3.3333, 3.3333, 3.3333], [3.3333, 3.3333, 3.3333, 3.3333, 3.3333]])