最近在用jupyter notebook做实验,但是每次notebook的cell只输出最后一个结果,如何让notebook的cell输出多个结果呢?
临时方案
在输出结果的cell前面加入以下代码:
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
永久解决方案(win10可用)
需要生成一个IPython配置文件,在cmd运行以下命令:
ipython profile create
再将以下代码写入C:\Users\ASUS.ipython\profile_default\ipython_config.py文件
c.InteractiveShell.ast_node_interactivity = "all"
我发现c = get_config()在新版本的Jupyter中没有必要 ,但是如果这对您不起作用,请将c = get_config()在文件的开头添加。
有关以外的其他标志选项"all",请访问以下链接:https : //ipython.readthedocs.io/en/stable/config/options/terminal.html#configtrait-InteractiveShell.ast_node_interactivity