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}
這將導致以下圖像:

添加回答
舉報
