On Sunday, January 14, 2018 at 3:28:02 AM UTC+5:30, bo...@questa.la.so wrote: > Rustom Mody 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
Thanks Well I had to tiny-tweak the code (import the display) --------------- import numpy as np from IPython.display import Latex, display 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))) --------------- After that it works… for 5 seconds!! ie it shows a nice centered matrix like a math-display in latex Then it goes away and I see a left aligned bunch of unicode boxes! -- https://mail.python.org/mailman/listinfo/python-list