brainconn.utils.matrix.weight_conversion

weight_conversion(W, wcm, copy=True)[source]

W_bin = weight_conversion(W, ‘binarize’); W_nrm = weight_conversion(W, ‘normalize’); L = weight_conversion(W, ‘lengths’);

This function may either binarize an input weighted connection matrix, normalize an input weighted connection matrix or convert an input weighted connection matrix to a weighted connection-length matrix.

Binarization converts all present connection weights to 1.

Normalization scales all weight magnitudes to the range [0,1] and should be done prior to computing some weighted measures, such as the weighted clustering coefficient.

Conversion of connection weights to connection lengths is needed prior to computation of weighted distance-based measures, such as distance and betweenness centrality. In a weighted connection network, higher weights are naturally interpreted as shorter lengths. The connection-lengths matrix here is defined as the inverse of the connection-weights matrix.

If copy is not set, this function will modify W in place.

Parameters:
  • W (NxN numpy.ndarray) – weighted connectivity matrix
  • wcm (str) – weight conversion command. ‘binarize’ : binarize weights ‘normalize’ : normalize weights ‘lengths’ : convert weights to lengths (invert matrix)
  • copy (bool) – if True, returns a copy of the matrix. Otherwise, modifies the matrix in place. Default value=True.
Returns:

W – connectivity matrix with specified changes

Return type:

NxN numpy.ndarray

Notes

This function is included for compatibility with BCT. But there are other functions binarize(), normalize() and invert() which are simpler to call directly.