How to mask tensor with boolean numpy array

I have a 84x84 pytorch tensor named target . I need to mask it with an 84x84 boolean numpy array which consists of True and False . This mask array is called mask.

When I do target = target[mask] , I get the error TypeError: can't convert np.ndarray of type numpy.bool_. The only supported types are: double, float, float16, int64, int32, and uint8.

Surprisingly, I get this error only when running on a GPU. When running on a CPU, everything works fine. How can I fix this?

Could you try to index with a tensor via:

target = target[torch.from_numpy(mask)]