def random_symmetric_matrix(n):
    _R = np.random.uniform(-1, 1, n * (n - 1) / 2)
P = np.zeros((n, n))
P[np.triu_indices(n, 1)] = _R
P[np.tril_indices(n, -1)] = P.T[np.tril_indices(n, -1)]
return P
Generating Symmetric Matrices in Numpy