Slicing with dask.array of bools

I'm trying to perform slicing using the following code:

import dask.array as da

x = da.random.random((10, 9, 8))
y = x.mean(axis=0)
z = x[:, y > 0.5]

Results in: NotImplementedError: Slicing with dask.array of bools only permitted when the indexer has only one dimension or when it has the same dimension as the sliced array

Is there a dask approved way of achieving the desired behavior? Thanks.

Hi @joshua-gould, welcome to Dask Discourse,

You’ve got some information on the slicing operations supported on this page.

I tried different approach to your problem, using map_blocks or trying to compute the mean first, but I didn’t find a valid one yet. I’ll ping some maintainers to have an advice, cc @fjetter @crusaderky.

Slicing by an n-dimensional array in numpy incorporates an implicit initial flattening step.
In dask you can do it by hand:

x = da.random.random((10, 9, 8))
y = x.mean(axis=0)
xflat = x.reshape(x.shape[0], -1)
yflat = y.ravel()
z = xflat[:, yflat > 0.5]
2 Likes