def matrix_to_edge_list(matrix, n):
    """Keep only the upper triangle of the adjacency matrix without its
    diagonal. Probably, should only be used in the case of an undirected graph.

    Parameters
    ----------
    matrix : list of a list
        Square adjacency matrix of an undirected graph.
    n : int
        The shape of the matrix should be (n, n, ).

    Returns
    -------
    list
        List of the graph edges. It's a list of dicts.
        i.e [{'nodes': (i1, j2), 'similarity': matrix[i1][j2]}, ...]

    """
    edge_list = []
    for i in range(n):
        for j in range(n):
            # consider only the upper triangle without the diagonal
            if j <= i:
                continue
            edge_list.append({
                'nodes': (i, j),
                'similarity': max(0, min(1, matrix[i][j]))
            })
    return edge_list