Here is one alternative way:
>>> m[np.triu_indices_from(m, k=1)] = mT[np.triu_indices_from(m, k=1)] >>> m array([[ 1. , 0.5, 0.6, 0.5], [ 0.5, 1. , 0. , 0.4], [ 0.6, 0. , 1. , 0.3], [ 0.5, 0.4, 0.3, 1. ]])
m[np.triu_indices_from(m, k=1)]
returns values ββabove the diagonal m
and assigns them to the values ββabove the diagonal transposition m
.
source share