【问题标题】:.ipynb Julia files to .jl files.ipynb Julia 文件到 .jl 文件
【发布时间】:2021-06-22 09:38:45
【问题描述】:

有没有一种方便的方法可以将使用 Jupyter notebook 生成的多个 .ipynb Julia 文件转换为 .jl 工作文件?

如果保留使用 Jupyter 编写的降价,但对我的使用不是强制性的,那很好。

这是我的文件包含的示例:

{
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Some useful functions required to build the model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "distance (generic function with 1 method)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Euclidean distances between point p1 and p2\n",
    "function distance(p1,p2)\n",
    "    dist=((p1[1]-p2[1])^2+(p1[2]-p2[2])^2)^(1/2)\n",
    "    return dist\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Tripletas (generic function with 1 method)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],

【问题讨论】:

    标签: file jupyter-notebook julia file-conversion


    【解决方案1】:

    有一个很方便的方法:jupytextThe docs 展示了如何在 jupyter 或 jupyterlab 和 at the command line 中使用它。

    例子:

    jupytext --to jl Notebook.ipynb
    

    在 shell 中,您可以执行以下操作:

    jupytext --to jl "path/to/notebooks/*.ipynb"
    

    【讨论】:

      【解决方案2】:

      您还可以在 Julia 中使用 NBInclude.jl 中的 nbexport 函数,例如

      using NBInclude
      nbexport("Notebook.jl", "Notebook.ipynb")
      

      它还可以在 Julia 中将 markdown 单元格转换为格式化和换行的 cmets。

      (请注意,此包还允许您直接从 Julia 使用 notebook 文件,无需转换。)

      【讨论】:

        猜你喜欢
        • 2014-04-10
        • 1970-01-01
        • 2016-09-30
        • 2013-12-09
        • 1970-01-01
        • 1970-01-01
        • 2020-12-09
        • 2016-07-24
        • 1970-01-01
        相关资源
        最近更新 更多