# so matrepr can be imported from the source tree.
import sys
sys.path.insert(0, '..')
from matrepr import mdisplay
import matrepr
matrepr.params.width_str = 115 # Narrow enough for GitHub's nb viewer
import scipy
row = [0, 0, 1, 2, 2, 3, 3, 3, 4]
col = [0, 1, 0, 2, 2, 3, 3, 3, 4]
val = [1, 12e34, 1e-6, 2.1, 2.2, 3.1, 3.2, 3.3, 0]
A = scipy.sparse.coo_array((val, (row, col)), shape=(5, 5))
mdisplay(A, "html")
0 | 1 | 2 | 3 | 4 | |
---|---|---|---|---|---|
0 | 1 | 1.2e+35 | |||
1 | 1e-06 | ||||
2 | 2.1 2.2 |
||||
3 | 3.1 3.2 3.3 |
||||
4 | 0 |
mdisplay(A, "latex")
mdisplay(A, "str")
<5×5, 9 'float64' elements, coo> 0 1 2 3 4 ┌ ┐ 0 │ 1 1.2e+35 │ 1 │ 1e-06 │ 2 │ [2.1, 2.2] │ 3 │ [3.1, 3.2, 3.3] │ 4 │ 0 │ └ ┘
import numpy as np
sps_mat = scipy.sparse.coo_array(([1, 2, 3, 4], ([0, 0, 1, 1], [0, 1, 0, 1])), shape=(2, 2))
dtype_a = np.dtype([("x", np.bool_), ("y", np.int64)], align=True)
np_a = np.array([(False, 2)], dtype=dtype_a)[0]
dtype_b = np.dtype("(3,)uint16")
np_b = np.array([(1, 2, 3)], dtype=dtype_b)[0]
np_2d = np.array([[11, 22], [33, 44]])
list_mat = [
(0, 12e34, 1e-6, None, 123456789),
1,
[complex(1, 2), complex(123456, 0.123456)],
[[1], sps_mat, [2.1, 2.2], [[1.1, 2.2], [3.3, 4.4]]],
["multiline\nstring", "<escape!>", "\\begin{escape!}", {"a Python set"}],
[np_a, np_b, np_2d]
]
row_labels = ["sci", "single", "complex", "nested", "strings", "numpy"]
col_labels = ["one", "two", "three", "four", "five"]
mdisplay(list_mat, "html", row_labels=row_labels, col_labels=col_labels)
one | two | three | four | five | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sci | 0 | 1.2e+35 | 1e-06 | 1.235e+08 | ||||||||||||
single | 1 | |||||||||||||||
complex | 1+2i | 1.235e05 + 0.1235i | ||||||||||||||
nested |
|
|
|
|
||||||||||||
strings | multiline string |
<escape!> | \begin{escape!} | {'a Python set'} | ||||||||||||
numpy | (False, 2) |
|
|
mdisplay(list_mat, "latex", row_labels=row_labels, col_labels=col_labels)
mdisplay(list_mat, "str", row_labels=row_labels, col_labels=col_labels)
<6×5, 18 elements, list> one two three four five ┌ ┐ sci │ 0 1.2e+35 1e-06 1.235e+08 │ single │ 1 │ complex │ 1+2i 1.235e05 + 0.1235i │ nested │ [1] [[1, 2], [3, 4]] [2.1, 2.2] [[1.1, 2.2], [3.3, 4.4]] │ strings │ 'multiline\nstring' '<escape!>' '\\begin{escape!}' {'a Python set'} │ numpy │ (False, 2) [1 2 3] [[11 22] [33 44]] │ └ ┘