我在JupyterLab中有一个代码,其中包含分布在多个单元格中的几个函数。第一个函数生成一个数据集,该数据集将在其后的所有其他函数中使用。
我要做的是两次运行相同的代码,但修改了其中一个功能。所以它看起来像这样:
data_generating_function() # this function should only be ran once so it generates the same dataset for both trials
function_1() # this is the function that is to be modified once, so there are two version of this function
function_2() # this function and all functions below it stay the same but should be ran twice
function_3()
function_4()
function_5()
因此,我将运行data_generating_function()
一次并生成数据集。然后,我将运行的一个版本function1()
及其下的所有功能,然后我将运行另一个版本的function1()
及其下的所有其他功能。
什么是实现此目标的好方法?很明显,我可以复制代码并仅更改一些函数名,也可以将其全部放入单个单元格中并创建一个for循环。但是,有没有一种更好的方法可以理想地保留多个单元呢?
谢谢
只需对第一个功能的两个选择进行迭代:
data_generating_function()
for func1 in (function1a, function1b):
func1()
function_2()
function_3()
function_4()
function_5()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句