def triang2mtx(xs: Vector, dim: int) -> Matrix:
"""
Transform a symmetric matrix represented as a flatten upper triangular
matrix to the correspoding 2-dimensional array.
"""
# New array
mtx = np.zeros((dim, dim))
# indexes of the upper triangular
inds = np.triu_indices_from(mtx)
# Fill the upper triangular of the new array
mtx[inds] = xs
# Fill the lower triangular
mtx[(inds[1], inds[0])] = xs
return mtx
评论列表
文章目录