python - 如何在 Jupyter Notebook 中强制执行代码执行顺序?
问题描述
观察到的行为
在已展示的 Jupyter Notebook 中,该笔记本产生以下输出:
ERP at 175 ms of trial 1
Average ERP at 175 ms of all trials
后附2张图:
<display image 0>
<display image 1>
当执行以下代码时:
z = sX_train[1,1,:,int(0.175*40)]
c="channels.txt"
print("ERP at 175 ms of trial 1")
topoplot(z,c)
# also compute the average ERP of all trials in first epoch at 180 ms
z = np.zeros(64)
for channel in range(0,z.shape[0]):
z[channel] = np.mean(sX_train[:,1,channel,int(0.175*40)])
print("Average ERP at 175 ms of all trials")
topoplot(z,c)
预期行为
但是,我希望输出为:
ERP at 175 ms of trial 1
<display image 0>
Average ERP at 175 ms of all trials
<display image 1>
如果要从上到下执行代码。
分析
我认为这是一些异步函数,因为计算topoplot
函数比计算打印语句需要更长的时间。但是我在线程或同步方面找不到任何东西。一个快速而肮脏的解决方案是修改拓扑图以返回一些东西,以便代码在打印描述之前必须等待它。
问题
如何确保输出按照在 Jupyter Notebook 的单元格中写入的顺序显示,而不修改代码以建立相互依赖关系?
解决方案
推荐阅读
- java - 如何设置 GIF 图像全屏 Android
- python - XML 从 URL 检索到 CSV
- java - Spring Batch 如何根据标题名称解析动态列?
- node.js - 如何使用ejs中的按钮通过_id查找和更新记录(MongoDB)?
- java - Hibernate search elasticsearch schema management NONE仍然连接到elasticsearch?
- javascript - 将画布存储为具有 .png 扩展名但在变量中的图像
- javascript - 带有 html 5 视频的 Slick Slider
- android - 如何在微调器上分配嵌套数组数据?
- list - 如何在 OCaml 中获取指向列表尾部的指针?
- arrays - 阵列有多少个不同的分区?