Locating the x,y coordinate of tensors for each batch

Please help. I want to find the x,y coordinate of certain values in a tensor with size N, C, H, W

For example, I have a tensor as shown below:

N, C, H, W = 51, 1, 7, 7
x = torch.randn(N, C, H, W)
x_mean = x.view(N, -1).mean(1, keepdim=True) #calculating the mean for every batch

Now, I want to find the (x,y) locations in the 1, 7, 7 array where the values are greater than the x_mean, for each batch.

This can be solved via broadcasting,

N, C, H, W = 51, 1, 7, 7
x = torch.randn(N, C, H, W)
x_mean = x.view(N, -1).mean(1, keepdim=True)

x_mean = x_mean.unsqueeze(2).unsqueeze(3) #unsqueeze to match dims
xy_locations = x > x_mean #boolean Tensor of which locations have a value greater than x_mean

I add xy = (xy_locations == True).nonzero(as_tuple=False) . Thank you.