How to display latex matrix as output of a code cell

twitter logo github logo ・1 min read

from IPython.display import display, Math

def print_matrix(array):
    data = ''
    for line in array:        
        if len(line) == 1:
            data += ' %.3f &'%line + r' \\\n'
        for element in line:
            data += ' %.3f &'%element
        data += r' \\' + '\n'
    display(Math('\\begin{bmatrix} \n%s\end{bmatrix}'%data))
twitter logo DISCUSS
Classic DEV Post from Jan 30

Make art, not apps <3

You don't have to build an app. In fact, if you don't need to, then don't.

r_tanaka profile image