使用 init_printing 在 Jupyter 笔记本单元中打印多个矩阵

问题描述 投票:0回答:1

我有两个矩阵想要使用 init_printing 在一个 jupyter 单元格中打印,当我尝试打印它们时,只打印最后一个。

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)
python jupyter-notebook sympy
1个回答
0
投票

这就是 jupyter-notebook 单元的工作原理,仅显示最后返回的输出。如果您两者都想要,请执行以下操作:

解决方案01

Matrix(L), Matrix(b)

输出:

解决方案02

现在,如果您确实坚持在下一行中依次打印,您可以使用

display
模块,如下所示:

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))

输出:

© www.soinside.com 2019 - 2024. All rights reserved.