osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Pandas printing in jupyter


Rustom Mody <rustompmody at gmail.com> writes:

> Specifically and for starters, I want a numpy array ? lets say 2D to
> start with ? to be displayed(displayable) as elegantly as sympy does
> to (its) matrices
########################################################################
import numpy as np
from IPython.display import Latex

def prmat(mat):
    return (r'\begin{bmatrix}' +
            r'\\'.join('&'.join('%f'%x for x in row) for row in mat) +
            r'\end{bmatrix}'

a = np.arange(12).reshape((3, 4))+1
display(Latex(prmat(a)))
########################################################################
you could add optional arguments to modify the type of brackets and the
formatting string