gpt4 book ai didi

python - 从 .py 转换为 .ipynb

转载 作者:行者123 更新时间:2023-12-03 13:44:43 33 4
gpt4 key购买 nike

我写了一个 juypter 笔记本,不知何故已转换为 .py。我希望它以原始格式返回。有谁知道这是怎么做到的吗?
之前有一个关于此的堆栈溢出问题,但该解决方案对我不起作用。 Converting to (not from) ipython Notebook format
下面是代码现在的示例。这是很多代码,因此手动复制和粘贴需要数小时。
谢谢您的帮助。

{
"cell_type": "code",
"execution_count": 581,
"metadata": {},
"outputs": [],
"source": [
"def add_trig_slope(data, size = 1, axis = 0, option = 0, random = False, lower_b = -1, upper_b = 2): \n",
" \n",
" # To make the gradual decline of the fuck you plot\n",
" ## sin, cos, tan, sigmoid, other activation functions?\n",
" # need to list the option in the doc string\n",
" \n",
" ## Add a random element\n",
" newdata = data.copy()\n",
" cols = list(newdata.columns)\n",
" funcs = [math.sin, math.cos, math.tan, expit]\n",
" func = funcs[option]\n",
" if axis == 0:\n",
" for col in cols:\n",
" newdata.loc[:, col] -= size * (func(cols.index(col)))\n",
" if random:\n",
" newdata.loc[:,col] -= np.random.uniform(lower_b,upper_b)\n",
"\n",
" elif axis == 1:\n",
" for i, node in enumerate(newdata.index):\n",
" newdata.loc[node,:] -= size * (func(i))\n",
" if random:\n",
" newdata.loc[node,:] -= np.random.uniform(lower_b,upper_b)\n",
"\n",
" \n",
" return newdata\n",
" \n",
" "
]

最佳答案

只需将其重命名即可更改扩展名
例如对于 linux/macos

mv <file>.py <file>.ipynb
或右键单击 Windows 的重命名并键入带有扩展名的全名
(因为内容似乎已经是 .ipynb 内容了)

关于python - 从 .py 转换为 .ipynb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62510114/

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