我有两个矩阵想要使用 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)
这就是 jupyter-notebook 单元的工作原理,仅显示最后返回的输出。如果您两者都想要,请执行以下操作:
Matrix(L), Matrix(b)
输出:
现在,如果您确实坚持在下一行中依次打印,您可以使用
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))
输出: