I have a 4d tensor that I need to perform some operations along the fourth dimension.

I have a 2d binary map for the first two dimensions, where I need to perform the operation only if it’s true.

I found that I can do this to get the sub tensor that I need to perform the operations on:

```
sub_patches=patches[binary_map, :, :]
```

which gives the desired time speed up.

but this combines the first two dimension, I need to put back where the values were.

Does anybody know how to do that?

Thanks