This page is a reference documentation. It only explains the function signature, and not how to use it. Please refer to the user guide for the big picture.

7.1.6. nilearn.connectome.vec_to_sym_matrix

nilearn.connectome.vec_to_sym_matrix(vec, diagonal=None)

Return the symmetric matrix given its flattened lower triangular part.

Acts on the last dimension of the array if not 1-dimensional. Diagonal can be encompassed in vec or given separately. In both cases, note that diagonal elements are multiplied by sqrt(2).

New in version 0.3.


vec : numpy.ndarray or list of numpy arrays, shape (…, n_columns * (n_columns + 1) /2) or

(…, (n_columns - 1) * n_columns / 2) if diagonal is given seperately. The input array.

diagonal : numpy.ndarray, shape (…, n_columns), optional

The diagonal array to be stacked to vec. If None, the diagonal is assumed to be included in vec.


sym : numpy.ndarray, shape (…, n_columns, n_columns).

The output symmetric matrix.


This function is meant to be the inverse of sym_matrix_to_vec. If you have discarded the diagonal in sym_matrix_to_vec, you need to provide it separately to reconstruct the symmetric matrix. For instance this can be useful for correlation matrices for which we know the diagonal is 1.