dynpy.mx - Matrix utilities module

Module which provides a consistent interface for working with both dense arrays and sparse matrices. Also constains some utility functions for working with matrices.

class dynpy.mx.StateBase[source]

Bases: object

Base class for managing objects which hold state of dynamical system

classmethod format_obj(obj)[source]

Format object obj into the current class’s preferred type (e.g., convert a dense matrix to sparse, or vice-versa, as appropriate)

classmethod vstack(data)[source]

Stack states vertically

class dynpy.mx.IntScalar[source]

Bases: StateBase

classmethod format_obj(obj)[source]

Format object obj into the current class’s preferred type (e.g., convert a dense matrix to sparse, or vice-versa, as appropriate)

classmethod vstack(data)[source]

Stack states vertically

class dynpy.mx.MxBase[source]

Bases: StateBase

Base class from which sparse and dense matrix operation classes inherit

classmethod format_obj(obj)[source]

Format object obj into the current class’s preferred type (e.g., convert a dense matrix to sparse, or vice-versa, as appropriate)

classmethod create_editable_zeros_mx(shape, dtype=None)[source]

Create blank editable transition matrix, of size specified by shape

classmethod finalize_mx(mx)[source]

Finalize processing of editable transition matrix mx

classmethod get_largest_right_eigs(mx)[source]

Get largest right eigenvectors and eigenvalues of matrix mx

classmethod get_largest_left_eigs(mx)[source]

Get largest left eigenvectors and eigenvalues of matrix mx

Returns:
1-dimensional numpy array

Eigenvalues

2-dimensional numpy array

Eigenvectors

classmethod pow(mx, exponent)[source]

Raise matrix mx to a power exponent

classmethod expm(mx)[source]

Return matrix exponential of matrix mx

classmethod make2d(mx)[source]

Transform matrix mx to be 2-dimensional

classmethod todense(mx)[source]

Convert matrix mx to dense format

classmethod tosparse(mx)[source]

Convert matrix mx to sparse format

classmethod isnan(mx)[source]

Element-wise isnan operation on matrix elements

classmethod array_equal(mx, other_mx)[source]

Return True if mx and other_mx are equal (including nan’s, unlike numpy’s array_equal

classmethod from_coords(rows, cols, data, shape)[source]

Initialize matrix using data and row, column coordinates. Duplicates should be summed

classmethod get_coords(mx)[source]

Return matrix in terms of data and row, column coordinates

classmethod diag(data)[source]

Returns matrix with diagonals set to data

classmethod getdiag(data)[source]

Returns diagonals of matrix

classmethod multiplyrows(mx, multiplier)[source]

TODO: Document

classmethod vstack(data)

Stack states vertically

class dynpy.mx.SparseMatrix[source]

Bases: MxBase

Class for sparse matrix operations. See documentation for dynpy.mx.MxBase for description of methods.

classmethod create_editable_zeros_mx(shape, dtype=None)[source]

Create blank editable transition matrix, of size specified by shape

classmethod format_mx(mx)[source]
classmethod finalize_mx(mx)[source]

Finalize processing of editable transition matrix mx

classmethod pow(mx, exponent)[source]

Raise matrix mx to a power exponent

classmethod expm(mx)[source]

Return matrix exponential of matrix mx

classmethod get_largest_right_eigs(mx)[source]

Get largest right eigenvectors and eigenvalues of matrix mx

classmethod make2d(mx)[source]

Transform matrix mx to be 2-dimensional

classmethod todense(mx)[source]

Convert matrix mx to dense format

classmethod tosparse(mx)[source]

Convert matrix mx to sparse format

classmethod isnan(mx)[source]

Element-wise isnan operation on matrix elements

classmethod from_coords(rows, cols, data, shape)[source]

Initialize matrix using data and row, column coordinates. Duplicates should be summed

classmethod get_coords(mx)[source]

Return matrix in terms of data and row, column coordinates

classmethod diag(data)[source]

Returns matrix with diagonals set to data

classmethod getdiag(mx)[source]

Returns diagonals of matrix

classmethod vstack(data)[source]

Stack states vertically

classmethod multiplyrows(mx, multiplier)[source]

TODO: Document

classmethod array_equal(mx, other_mx)

Return True if mx and other_mx are equal (including nan’s, unlike numpy’s array_equal

classmethod format_obj(obj)

Format object obj into the current class’s preferred type (e.g., convert a dense matrix to sparse, or vice-versa, as appropriate)

classmethod get_largest_left_eigs(mx)

Get largest left eigenvectors and eigenvalues of matrix mx

Returns:
1-dimensional numpy array

Eigenvalues

2-dimensional numpy array

Eigenvectors

class dynpy.mx.DenseMatrix[source]

Bases: MxBase

Class for dense matrix operations. See documentation for dynpy.mx.MxBase for description of methods.

classmethod expm(mx)[source]

Return matrix exponential of matrix mx

classmethod get_largest_right_eigs(mx)[source]

Get largest right eigenvectors and eigenvalues of matrix mx

classmethod create_editable_zeros_mx(shape, dtype=None)[source]

Create blank editable transition matrix, of size specified by shape

classmethod format_mx(mx)[source]
classmethod finalize_mx(mx)[source]

Finalize processing of editable transition matrix mx

classmethod pow(mx, exponent)[source]

Raise matrix mx to a power exponent

classmethod make2d(mx)[source]

Transform matrix mx to be 2-dimensional

classmethod todense(mx)[source]

Convert matrix mx to dense format

classmethod tosparse(mx)[source]

Convert matrix mx to sparse format

classmethod isnan(mx)[source]

Element-wise isnan operation on matrix elements

classmethod array_equal(mx, other_mx)[source]

Return True if mx and other_mx are equal (including nan’s, unlike numpy’s array_equal

classmethod from_coords(rows, cols, data, shape)[source]

Initialize matrix using data and row, column coordinates. Duplicates should be summed

classmethod get_coords(mx)[source]

Return matrix in terms of data and row, column coordinates

classmethod diag(data)[source]

Returns matrix with diagonals set to data

classmethod getdiag(mx)[source]

Returns diagonals of matrix

classmethod vstack(data)[source]

Stack states vertically

classmethod multiplyrows(mx, multiplier)[source]

TODO: Document

classmethod format_obj(obj)

Format object obj into the current class’s preferred type (e.g., convert a dense matrix to sparse, or vice-versa, as appropriate)

classmethod get_largest_left_eigs(mx)

Get largest left eigenvectors and eigenvalues of matrix mx

Returns:
1-dimensional numpy array

Eigenvalues

2-dimensional numpy array

Eigenvectors

dynpy.mx.issparse(mx)[source]
dynpy.mx.get_state_cls(obj)[source]
dynpy.mx.get_matrix_cls(mx)[source]
dynpy.mx.format_mx(mx)[source]
dynpy.mx.finalize_mx(mx)[source]
dynpy.mx.pow(mx, exponent)[source]
dynpy.mx.expm(mx)[source]
dynpy.mx.make2d(mx)[source]
dynpy.mx.todense(mx)[source]
dynpy.mx.tosparse(mx)[source]
dynpy.mx.get_largest_right_eigs(mx)[source]
dynpy.mx.get_largest_left_eigs(mx)[source]
dynpy.mx.isnan(mx)[source]
dynpy.mx.array_equal(mx, other_mx)[source]
dynpy.mx.getdiag(mx)[source]
dynpy.mx.multiplyrows(mx, multiplier)[source]
class dynpy.mx.hashable_array(data)[source]

Bases: ndarray

This class provides a hashable and sortable np.array. This is useful for using np.array as dicitionary keys, for example.

Notice that hashable arrays change the default behavior of numpy arrays for equality and comparison operators. Instead of performing element-wise tests, hashable arrays return a value for the array as a whole

dynpy.mx.hashable_state(x)[source]