2 回答

TA贡献1797条经验 获得超6个赞
Matplotlib 可以使用 LaTeX 渲染文本,因此您可以利用它来进行这种可视化:
import numpy as np
import matplotlib.pyplot as plt
def show_mat(a, font_size, resolution=None, dpi=None):
resolution = resolution or (600, 400)
dpi = dpi or 100
res_x, res_y = resolution
inc_x = res_x / dpi
inc_y = res_y / dpi
rows, cols = a.shape
fig = plt.figure(figsize=(inc_x, inc_y), dpi=dpi)
ax = fig.add_subplot(111)
ax.set_axis_off()
a_str = r' \\ '.join(' & \quad & '.join(map(str, row)) for row in a)
alig = 'c' * (2 * cols - 1)
tex = r"$\left[\begin{{array}}{{{}}}{}\end{{array}}\right]$".format(alig, a_str)
ax.text(0.5, 0.5, tex, size=font_size,
horizontalalignment='center', verticalalignment='center',
transform=ax.transAxes)
show_mat(np.arange(1, 10).reshape(3, 3), font_size=50)
输出:

TA贡献1865条经验 获得超7个赞
您使用的 Kaggle 内核似乎无法访问 LaTex 解释器。
如果您只想为演示文稿创建一些图像,您可以查看Latex 2 png。在这里你必须输入
\begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{bmatrix}
这将导致以下图像:
添加回答
举报