Test if a 3D (H,W,C) matrix x has the same element in each (H,W) matrix for each channel

def _same_elements_per_channel(x):
    """
    Test if a 3D (H,W,C) matrix x has the same element in each (H,W) matrix for each channel
    """
    eps = 1e-5
    dims = x.shape
    for c in range(dims[-1]):
        xc = x[:,:,c].flatten()
        if not np.all(np.absolute(xc - xc[0]) < eps):
            return False
    return True