Thanks! I think this could work. Do you know how to do this over say dim=1 in the case of 4 dimensions?

a = torch.randn(3, 2, 4, 4)
th = torch.randn(1, 2, 1, 1)
idx = (a > th).float()   #over dim=1 <idx would be shape (3,2,4,4)>

I could always permute the data to make it two dimensions as in your example, but I think that would be a bit slower.
Edit: Disregard this comment – I didn’t realize the semantics already work this way!