Solved by ptrblck in post #2 
              
              
                You could use broadcasting to get the desired result: 
x = torch.tensor([[[1., 3.],
                   [2., 4.]],
                  [[5., 7.],
                   [9., 8.]]])

quantile = torch.tensor([torch.quantile(a, 1/2) for a in x])

res = torch.where(x > quantile[:, None, None], 1, 0)
print(res)…