Note
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.
nilearn.connectome.sym_matrix_to_vec¶
- nilearn.connectome.sym_matrix_to_vec(symmetric, discard_diagonal=False)[source]¶
Return the flattened lower triangular part of an array.
If diagonal is kept, diagonal elements are divided by sqrt(2) to conserve the norm.
Acts on the last two dimensions of the array if not 2-dimensional.
Added in Nilearn 0.3.
- Parameters:
- Returns:
- outputnumpy.ndarray
The output flattened lower triangular part of symmetric. Shape is (…, n_features * (n_features + 1) / 2) if discard_diagonal is False and (…, (n_features - 1) * n_features / 2) otherwise.
Examples
>>> import numpy as np >>> sym_matrix = np.array([[1.0, 2.0, 3.0], ... [2.0, 1.0, 5.0], ... [3.0, 5.0, 1.0]])
Diagonal elements (all 1.0 here) are divided by sqrt(2):
>>> from nilearn.connectome import sym_matrix_to_vec >>> vec = sym_matrix_to_vec(sym_matrix) >>> vec array([0.70710678, 2. , 0.70710678, 3. , 5. , 0.70710678])
Discard_diagonal=True drops the diagonal entries entirely:
>>> vec_no_diag = sym_matrix_to_vec(sym_matrix, discard_diagonal=True) >>> vec_no_diag array([2., 3., 5.])