cf.indices_shape

cf.indices_shape(indices, full_shape, keepdims=True)[source]

Return the shape of the array subspace implied by indices.

Performance

Boolean dask arrays will be computed, and dask arrays with unknown size will have their chunk sizes computed.

New in version 3.14.0.

See also

cf.parse_indices

Parameters
indices: tuple

The indices to be applied to an array with shape full_shape.

full_shape: sequence of ints

The shape of the array to be subspaced.

keepdims: bool, optional

If True then an integral index is converted to a slice. For instance, 3 would become slice(3, 4).

Returns
list

The shape of the subspace defined by the indices.

Examples

>>> import numpy as np
>>> import dask.array as da
>>> cf.indices_shape((slice(2, 5), 4), (10, 20))
[3, 1]
>>> cf.indices_shape(([2, 3, 4], np.arange(1, 6)), (10, 20))
[3, 5]
>>> index0 = [False] * 5
>>> index0[2:5] = [True] * 3
>>> cf.indices_shape((index0, da.arange(1, 6)), (10, 20))
[3, 5]
>>> index0 = da.full((5,), False, dtype=bool)
>>> index0[2:5] = True
>>> index1 = np.full((6,), False, dtype=bool)
>>> index1[1:6] = True
>>> cf.indices_shape((index0, index1), (10, 20))
[3, 5]
>>> index0 = da.arange(5)
>>> index0 = index0[index0 < 3]
>>> cf.indices_shape((index0, []), (10, 20))
[3, 0]
>>> cf.indices_shape((da.from_array(2), np.array(3)), (10, 20))
[1, 1]
>>> cf.indices_shape((da.from_array([]), np.array(())), (10, 20))
[0, 0]
>>> cf.indices_shape((slice(1, 5, 3), 3), (10, 20))
[2, 1]
>>> cf.indices_shape((slice(5, 1, -2), 3), (10, 20))
[2, 1]
>>> cf.indices_shape((slice(5, 1, 3), 3), (10, 20))
[0, 1]
>>> cf.indices_shape((slice(1, 5, -3), 3), (10, 20))
[0, 1]
>>> cf.indices_shape((slice(2, 5), 4), (10, 20), keepdims=False)
[3]
>>> cf.indices_shape((da.from_array(2), 3), (10, 20), keepdims=False)
[]
>>> cf.indices_shape((2, np.array(3)), (10, 20), keepdims=False)
[]