giddy.util.get_lower

giddy.util.get_lower(matrix)[source]

Flattens the lower part of an n x n matrix into an n*(n-1)/2 x 1 vector.

Parameters:
matrixarray

(n, n) numpy array, a distance matrix.

Returns:
lowvecarray

numpy array, the lower half of the distance matrix flattened into a vector of length n*(n-1)/2.

Examples

>>> import numpy as np
>>> from giddy.util import get_lower
>>> test = np.array([[0,1,2,3],[1,0,1,2],[2,1,0,1],[4,2,1,0]])
>>> lower = get_lower(test)
>>> lower
array([[1],
       [2],
       [1],
       [4],
       [2],
       [1]])