gpt4 book ai didi

ipython-notebook - 在 IPython Notebook 中显示作业结果?

转载 作者:行者123 更新时间:2023-12-05 03:12:42 25 4
gpt4 key购买 nike

我正在用 ipython notebook 写一个热传递问题的方程式/赋值链(我是新手),像这样:

# nominal diameter
d=3.55 # m
# ambient temperature
T0=15 # C
# surface temperature
Tw=300 # C
# average film temperature
Tm=(T0+Tw)/2+273.15 # K!
# expansion coefficient, $$\beta=1/T$$ for ideal gas
beta=1./Tm
# temperature difference
dT=Tw-T0 # C or K

有没有办法回显每个分配,以便显示那些(主要是计算的)值?我知道 %whos 魔法,但它按字母顺序显示变量。

理想情况下,我想得到这样的东西:

# nominal diameter
d=3.55 # m
3.55
# ambient temperature
T0=15 # C
15
# surface temperature
Tw=300 # C
300
# average film temperature
Tm=(T0+Tw)/2+273.15 # K!
430.15
# expansion coefficient, $$\beta=1/T$$ for ideal gas
beta=1./Tm
0.00232477042892
# temperature difference
dT=Tw-T0 # C or K
285

可能带有输入/输出提示(我不介意)和语法高亮显示。

用 IPython 记录计算的正确方法是什么?

最佳答案

这个特征是not IPython 核心功能的一部分。它已被并入扩展 displaytools .引用自 repo 协议(protocol):

Load this extension with %load_ext displaytools or %reload_ext
displaytools
. The latter is useful for debugging.

Example invocation:

my_random_variable = np.random.rand() ##

Due to the special comment ## the extension inserts the line display(my_random_variable) to the source code, before it is passed to the interpreter, i.e. before its execution.

That way, additional output is generated, which makes the notebook be more comprehensible (because the reader knows the content of my_random_variable). It saves the typing effort and the code duplication of manually adding display(my_random_variable).

关于ipython-notebook - 在 IPython Notebook 中显示作业结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32839954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com