I’m not completely understand the use case.
If you are using a threshold on b, you might only have a single True output in idx.
Indexing a with this idx tensor would return an output of [1, X, Y], not [B, 1, X, Y].
Could you explain a bit, how the threshold should be applied to b?
Currently it seems that you are setting the same values for all elements in dim0.