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 Sep 17 '18

Who's looking for open source contributors? (September 17 edition)

Find something to work on or promote your project here. Please shamelessly pro...

r_tanaka profile image

Tip: You can configure your reading experience, such as using sans serif fonts.

Go to your the "misc." section of your settings.