Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using init_printing to print multiple Matrices in a in Jupyter notebook cell

I have two matrices that want to print in one jupyter cell using init_printing, When I try printing them both only the last one gets printed.

import numpy as np 
from sympy import init_printing, Matrix

L = np.array([[1, 0, 0], [2, 1, 0], [-1, 0.5, -1]])
b = np.array([2, 4, 2])

Matrix(L)
Matrix(b)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

that’s how jupyter-notebook cells work, only the last returned output will be shown. If you want both, do:

solution 01

Matrix(L), Matrix(b)

Output:

enter image description here

solution 02

Now, if you do insist to print one after another in the next line, you can use the display module like this:

from IPython.display import display
import numpy as np 
from sympy import Matrix

L = np.array([[1, 0, 0], [2, 1, 0], [-1, 0.5, -1]])
b = np.array([2, 4, 2])

display(Matrix(L))
display(Matrix(b))

Output:

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading