def symmetrise ( matrix , tri = 'upper' ) : if tri == 'upper' : tri_fn = np . triu_indices else : tri_fn = np . tril_indices size = matrix . shape [ 0 ] matrix [ tri_fn ( size ) [ : : - 1 ] ] = matrix [ tri_fn ( size ) ] return matrix
how to seperate the matrix to upper triagle python
Will copy the selected ( upper or lower ) triangle of a square matrix to the opposite side so that the matrix is symmetrical . Alters in place .
def symmetrise(matrix, tri='upper'):
    """
    Will copy the selected (upper or lower) triangle of a square matrix
    to the opposite side, so that the matrix is symmetrical.
    Alters in place.
    """
    if tri == 'upper':
        tri_fn = np.triu_indices
    else:
        tri_fn = np.tril_indices
    size = matrix.shape[0]
    matrix[tri_fn(size)[::-1]] = matrix[tri_fn(size)]
    return matrix