从.py转换为.ipynb [英] converting from .py to .ipynb

查看:1333
本文介绍了从.py转换为.ipynb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个juypter笔记本,它已经以某种方式转换为.py.我希望它恢复原始格式.有人知道怎么做吗?

I wrote a juypter notebook that has been converted to .py somehow. I would like it back in the original format. Does anyone know how to do that?

关于此的先前的堆栈溢出问题,但是该解决方案对我不起作用. 转换为(不是来自)ipython Notebook格式

There is a previous stack overflow question about this, but the solution doesn't work for me. Converting to (not from) ipython Notebook format

下面是该代码现在的示例.这是很多代码,因此手动复制和粘贴将花费数小时.

The below is an example of what the code looks like now. It is a lot of code so would take hours to copy and paste it manually.

感谢您的帮助.

{
   "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

Just rename it changing the extension e.g. for linux/macos

mv <file>.py <file>.ipynb

或右键单击Windows重命名,然后输入带扩展名的全名

or right-click rename for windows and type the full name with the extension

(因为该内容似乎已经是.ipynb内容)

(Since it seems that the contents are .ipynb contents already)

这篇关于从.py转换为.ipynb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆