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'
            continue
        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 Dec 5 '17

JavaScript is almost pythonic

Multi-line String Python3.6 print("""string text line 1 string ...

r_tanaka profile image

👋 Hey dev.to reader.

Do you prefer sans serif over serif?

You can change your font preferences in the "misc" section of your settings. ❤️