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:
  • style (str, optional) – Bracket format, defaults to “thin”

  • fmt (str, optional) – number format string, defaults to “{:< 10.3g}”

  • squish (int, optional) – elements smaller than this times eps are displayed as zero, defaults to 100

Creates a formatter, or template, for formatting matrices.

from ansitable import ANSIMatrix
import numpy as np

formatter = ANSIMatrix(style='ascii')
m = np.random.rand(4,4) - 0.5
formatter.print(m)

+                                           +
| 0.23      -0.00542   -0.282      0.229    |
| 0.433      0.229      0.489     -0.414    |
| 0.0901    -0.351     -0.413     -0.418    |
| 0.433      0.233      0.0495     0.000281 |
+                                           +
str(matrix, suffix_super='', suffix_sub='')[source]

Output the table as a string

Parameters:
  • matrix (1d or 2d ndarray) – NumPy matrix to format

  • suffix_super (str, optional) – Right superscript, defaults to ‘’

  • suffix_sub (str, optional) – Right subscript, defaults to ‘’

Raises:

ValueError – [description]

Returns:

ANSI string

Return type:

str

suffix_super is where the transpose, inverse, pseudo-inverse, etc. symbol is shown. suffix_sub is where the matrix name is typically shown.

print(matrix, *pos, file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, **kwargs)[source]

Print the matrix

Parameters:

file (writeable object, optional) – Print the matrix to this file, defaults to stdout

Note

Accepts the same arguments as str.