import torch


def create_matrix(n, device):
    """
    :param n: matrix size (class num)
    :param device:
    :return a matrix with torch.tensor type:
    for example n=3:
    1     -1/2  -1/2
    -1/2    1   -1/2
    -1/2  -1/2    1
    """

    eye = torch.eye(n, device=device)
    return eye - (torch.ones((n, n), device=device) - eye) / (n - 1)