Great!
I’ve used None to unsqueeze the tensor. Alternatively, you could use .mean(2).unsqueeze(2).unsqueeze(3), but I prefer to use this notation if I need to add more than one dimension.
In older versions this will probably work:
z = x.clone()
z[x > x.view(B, C, -1).mean(2)[:, :, None, None]] = 1.
z[x <= x.view(B, C, -1).mean(2)[:, :, None, None]] = 0.

I’ve compared it to the first solution and it yields the same result.