MatrixTools.py -

Tags

Python

Code

MatrixTools.addOptions(parser)

add matrices to option parser.

MatrixTools.getMatrixFromEdges(lines, options, in_map_token2row={}, in_map_token2col={})

read matrix from lines

MatrixTools.buildMatrixFromLists(lists, dtype=<class 'float'>, default=None)

build a matrix from a list of lists.

Each list is a list of tuples (row, value). The columns are given by order of the lists.

Returns matrix, row_headers

MatrixTools.buildMatrixFromTables(infiles, column, column_header=0, dtype=<class 'float'>, default=None)

build a matrix from a column called column in a series of input files.

If column_value is None, the first column is taken as the name of the row.

The columns are given by order of the input files.

returns matrix, row_headers

MatrixTools.buildMatrixFromEdges(edges, in_map_token2row={}, in_map_token2col={}, is_symmetric=False, missing_value=0, diagonal_value=0, dtype=<class 'int'>)

build a matrix from an edge-list representation.

For example, the following list of tuples:

[('A', 'B', 1),
 ('A', 'C', 2),
 ('B', 'C', 3)]

will be converted to the following matrix:

  A B C
A   1 2
B     3
C

If is_symmetric is set to True, the matrix is assumed to be symmetric and missing values will automatically be filled:

  A B C
A   1 2
B 1   3
C 2 3

If edge list may contain four elements, in which case the fourth element is expected to be the value of the lower diagonal in a symmetric matrix:

[('A', 'B', 1, 4),
 ('A', 'C', 2, 5),
 ('B', 'C', 3, 6)]

will yield:

  A B C
A   1 2
B 4   3
C 5 6

returns a numpy matrix and lists of row and column names.