jupyter notebook中美观显示矩阵实例
2020-04-18 07:11
871 查看
我就废话不多说了,还是直接看代码吧!
from IPython.display import display,Latex,Math %matplotlib inline from IPython.core.interactiveshell import InteractiveShell sh = InteractiveShell.instance() def number_to_str(n,cut=5): ns=str(n) format_='{0:.'+str(cut)+'f}' if 'e' in ns or ('.' in ns and len(ns)>cut+1): return format_.format(n) else: return str(n) def matrix_to_latex(mat,style='bmatrix'): if type(mat)==np.matrixlib.defmatrix.matrix: mat=mat.A head=r'\begin{'+style+'}' tail=r'\end{'+style+'}' if len(mat.shape)==1: body=r'\\'.join([str(el) for el in mat]) return head+body+tail elif len(mat.shape)==2: lines=[] for row in mat: lines.append('&'.join([number_to_str(el) for el in row])+r'\\') s=head+' '.join(lines)+tail return s return None sh.display_formatter.formatters['text/latex'].type_printers[np.ndarray]=matrix_to_latex
输入后运行即可
我们在进行矩阵打印的时候就相当美观咯!!!
补充知识:解决python numpy 大数组显示不全的问题
import numpy as np
np.set_printoptions(threshold=np.inf)
或者
np.set_printoptions(threshold='nan')
其中threshold表示:
Total number of array elements to be print(输出数组的元素数目)
以上这篇jupyter notebook中美观显示矩阵实例就是小编分享给大家的全部内容了,希望能给大家一个参考
您可能感兴趣的文章:
相关文章推荐
- ipython jupyter notebook中显示图像和数学公式实例
- 【matplotlib】windows系统解决jupyter notebook中文显示问题
- IPython notebook(Jupyter notebook)如何显示已安装的内核
- jupyter notebook 参数传递给shell命令行实例
- jupyter notebook 多行输出实例
- jupyter notebook中,用matplotlib绘图中文显示乱码(亲测有效!)
- jupyter notebook显示plot图像
- 从jupyter notebook下导入pydot的时候显示错误
- jupyter notebook,ipynb文件与py文件在matplotlib显示输出差异
- jupyter notebook在网页上显示作图
- 解决jupyter notebook显示不全出现框框或者乱码问题
- 如何将Jupyter Notebook(.ipynb文件)导出为支持中文显示的PDF
- 如何调整jupyter notebook行间显示图片的大小
- jupyter notebook显示不全出现框框或者乱码解决方案
- jupyter notebook画图中文标题显示乱码。
- 在google cloud的VM实例中部署jupyter notebook并在本地浏览器中打开(二)
- jupyter notebook目录显示
- 在jupyter notebook取消matplotlib的独立窗口显示
- Jupyter notebook 转成pdf 中文显示、代码隐藏
- Jupyter Notebook 使用IE打开显示不出界面的问题