Matrix class
This class describes a block diagram, a collection of blocks and wires that can be “executed”.
- class ansitable.table.ANSIMatrix(style='thin', fmt='{:< 10.3g}', squish=100)[source]
Bases:
object- __init__(style='thin', fmt='{:< 10.3g}', squish=100)[source]
Create a matrix formatter
- Parameters:
Creates a formatter, or template, for formatting matrices.
Border
Description
ascii
Use ASCII +-| characters
thin
Use ANSI thin box-drawing characters
round
Use ANSI thin box-drawing characters with rounded corners
thick
Use ANSI thick box-drawing characters
double
Use ANSI double-line box-drawing characters
Example:
>>> from ansitable import ANSIMatrix >>> import numpy as np >>> np.random.seed(0) >>> formatter = ANSIMatrix(style="ascii") >>> m = np.random.rand(4, 4) - 0.5 >>> formatter.print(m) + + | 0.0488 0.215 0.103 0.0449 | |-0.0763 0.146 -0.0624 0.392 | | 0.464 -0.117 0.292 0.0289 | | 0.068 0.426 -0.429 -0.413 | + +
- str(matrix, suffix_super='', suffix_sub='')[source]
Output the table as a string
- Parameters:
- Raises:
ValueError – if the array has more than 2 dimensions
- Return type:
suffix_superis where the transpose, inverse, pseudo-inverse, etc. symbol is shown.suffix_subis where the matrix name is typically shown.Example:
>>> from ansitable import ANSIMatrix >>> import numpy as np >>> np.random.seed(0) >>> formatter = ANSIMatrix(style="ascii") >>> m = np.random.rand(4, 4) - 0.5 >>> print(formatter.str(m)) + + | 0.0488 0.215 0.103 0.0449 | |-0.0763 0.146 -0.0624 0.392 | | 0.464 -0.117 0.292 0.0289 | | 0.068 0.426 -0.429 -0.413 | + +
- print(matrix, *pos, file=None, **kwargs)[source]
Print the matrix
- Parameters:
file (TextIO | None) – Print the matrix to this file, defaults to stdout
- Return type:
None
Note
Accepts the same arguments as
str.Example:
>>> from ansitable import ANSIMatrix >>> import numpy as np >>> np.random.seed(0) >>> formatter = ANSIMatrix(style="ascii") >>> m = np.random.rand(4, 4) - 0.5 >>> formatter.print(m, suffix_super="T", suffix_sub="3") + +T | 0.0488 0.215 0.103 0.0449 | |-0.0763 0.146 -0.0624 0.392 | | 0.464 -0.117 0.292 0.0289 | | 0.068 0.426 -0.429 -0.413 | + +3