Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我应该如何修改JSON元数据,以便在jupyter笔记本中打开ipynb文件?_Python_Json_Jupyter Notebook_Kernel_Jupyter - Fatal编程技术网

Python 我应该如何修改JSON元数据,以便在jupyter笔记本中打开ipynb文件?

Python 我应该如何修改JSON元数据,以便在jupyter笔记本中打开ipynb文件?,python,json,jupyter-notebook,kernel,jupyter,Python,Json,Jupyter Notebook,Kernel,Jupyter,我无法再在VS Code jupyter笔记本中打开ipynb文件。我有一个问题,这一个特定的文件,因为我的其他文件打开没有问题。我认为问题来自元数据中的错误,因为此文件中的元数据与成功打开的其他文件的元数据结构非常不同 该文件过去打开时没有任何故障,但现在当我尝试打开该文件时,我看到以下错误: 命令失败:C:/Users/Tony/anaconda3/Scripts/activate&&conda activate base&&echo'e8b39361-0157-4923-80e1-22d7

我无法再在VS Code jupyter笔记本中打开ipynb文件。我有一个问题,这一个特定的文件,因为我的其他文件打开没有问题。我认为问题来自元数据中的错误,因为此文件中的元数据与成功打开的其他文件的元数据结构非常不同

该文件过去打开时没有任何故障,但现在当我尝试打开该文件时,我看到以下错误:

命令失败:C:/Users/Tony/anaconda3/Scripts/activate&&conda activate base&&echo'e8b39361-0157-4923-80e1-22d70d46dee6'&&python C:\Users\Tony.vscode\extensions\ms python.python-2020.9.112786\pythonFiles\pyvsc-run-isolated.pyc:/Users/Tony/.vscode/extensions/ms python.python-2020.9.112786/pythonFiles/printEnvVariables.py

 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.8.3 64-bit ('base': conda)",
   "language": "python",
   "name": "python_defaultSpec_1597947257101"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3-final"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
来源:Python(扩展)

我的理解是VS代码找不到指定的python解释器,这反过来会阻止内核被激活。(我不是很有经验,如果我错了,请纠正我!)

我尝试过将python解释器从文件复制粘贴到损坏的文件中,但没有成功

请参阅下面损坏的JSON文件的副本,以及成功打开的ipynb文件的元数据结构示例

非常感谢所有在这方面的帮助

非常感谢,托尼

损坏的JSON文件

{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "numpy_random.ipynb",
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "lhmyI7sB_bKJ",
        "colab_type": "text"
      },
      "source": [
        "# Generate Random Numbers"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "MulyzIdD_kxf",
        "colab_type": "text"
      },
      "source": [
        "`numpy.random` is frequently used for generating random numbers.\n",
        "\n",
        "For more details, please refer to [Random sampling (numpy.random)](https://docs.scipy.org/doc/numpy/reference/routines.random.html)"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vtrQ-n7PAoYJ",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import numpy as np"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "nLB8lH051pDg",
        "colab_type": "text"
      },
      "source": [
        "`np.random.seed` sets the seed for the generator."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "PzxXe5pR3QI0",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "np.random.seed(1)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "cSSX-VCBAnuJ",
        "colab_type": "text"
      },
      "source": [
        "`np.random.rand` generates numbers uniformly distribution over $[0, 1)$"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ran81EdeAKl6",
        "colab_type": "code",
        "outputId": "9adb1089-0417-490b-f31e-6730df35d688",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 53
        }
      },
      "source": [
        "np.random.rand(2, 3) # Generate 2 * 3 random numbers"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[4.17022005e-01, 7.20324493e-01, 1.14374817e-04],\n",
              "       [3.02332573e-01, 1.46755891e-01, 9.23385948e-02]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 18
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "g_jgVxcfAi00",
        "colab_type": "text"
      },
      "source": [
        "`np.radnom.randn` generates numbers following standard normal distribtion."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "OG-suj-PA72b",
        "colab_type": "code",
        "outputId": "6fda962e-bc37-4f93-9bdf-aa82b5502117",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 53
        }
      },
      "source": [
        "np.random.randn(2, 3) # Generate 2 * 3 random numbers"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[-0.52817175, -1.07296862,  0.86540763],\n",
              "       [-2.3015387 ,  1.74481176, -0.7612069 ]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 19
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "SLw958olA9Uu",
        "colab_type": "text"
      },
      "source": [
        "`np.random.randint(low, high)` generates integers ranging from `low` (inclusive) to `high` (exclusive)"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "SkRVwD_yCd7r",
        "colab_type": "code",
        "outputId": "72c58ee8-4ed7-433e-8a95-60e58293f827",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 71
        }
      },
      "source": [
        "np.random.randint(low = 0, high = 4, size = (3, 3))"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[3, 0, 2],\n",
              "       [0, 1, 2],\n",
              "       [2, 0, 3]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 20
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "MLSvOE4UEA6n",
        "colab_type": "text"
      },
      "source": [
        "`np.random.choice` geneates random numbers following a given pmf."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "NidDNwzK4FRY",
        "colab_type": "code",
        "outputId": "13962d5d-09fb-41cb-fe32-e90186c6bfcd",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 71
        }
      },
      "source": [
        "a = np.arange(4)\n",
        "p = [0.1, 0.2, 0.3, 0.4]\n",
        "np.random.choice(a = a, size=(3, 4), p = p)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[2, 2, 3, 3],\n",
              "       [3, 3, 0, 2],\n",
              "       [3, 3, 3, 1]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 21
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "9Arc1wQq5a2V",
        "colab_type": "text"
      },
      "source": [
        "The sample space is not necessary to be number sets."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "7JqVclm44hgH",
        "colab_type": "code",
        "outputId": "fc86099d-f55f-4d9c-f75f-930e91160710",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 71
        }
      },
      "source": [
        "a = ['Spade', 'Heart', 'Clud', 'Diamond']\n",
        "p = [0.25, 0.25, 0.25, 0.25]\n",
        "np.random.choice(a = a, size=(3, 4), p = p)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([['Spade', 'Clud', 'Clud', 'Clud'],\n",
              "       ['Heart', 'Spade', 'Heart', 'Spade'],\n",
              "       ['Diamond', 'Heart', 'Spade', 'Clud']], dtype='<U7')"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 22
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "O7pLtNHP5XbL",
        "colab_type": "text"
      },
      "source": [
        "It is also possible to draw random samples from other distributions."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Wa7KH_rW6WaU",
        "colab_type": "text"
      },
      "source": [
        "Exponential: $f_X(x; \\beta) = \\frac{1}{\\beta}e^{-\\frac{x}{\\beta}}$, $\\beta$ is the scale parameter."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "fstao_qt6Yn7",
        "colab_type": "code",
        "outputId": "e44f81bf-1d3f-4e52-c19b-969cd1da70e0",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 53
        }
      },
      "source": [
        "np.random.exponential(scale = 2, size = (2, 3))"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[2.16136241, 0.70905534, 1.18166682],\n",
              "       [0.50237771, 0.15238928, 1.26688512]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 23
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "cS-2YNh162s8",
        "colab_type": "text"
      },
      "source": [
        "Binomial: $P_X(k; n,p) = \\binom{n}{k} p^k (1 - p)^{n - k}$."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "QCNVWxTx7Utf",
        "colab_type": "code",
        "outputId": "31fbcc4b-4710-4c67-9ffc-2921a5ddf7e7",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 71
        }
      },
      "source": [
        "n = 10\n",
        "p = 0.8\n",
        "np.random.binomial(n = n, p = p, size = (3, 3))"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[10,  6,  9],\n",
              "       [ 8, 10,  6],\n",
              "       [ 6,  9,  8]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 24
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "e16J3-el71gV",
        "colab_type": "text"
      },
      "source": [
        "More distribution types are shown in the docs. "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "jkt_2jWu8DBe",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        ""
      ],
      "execution_count": 0,
      "outputs": []
    }
  ]
}

我通过从损坏的文件中删除元数据解决了这个问题。这是我删除的元数据

"metadata": {
    "colab": {
      "name": "numpy_random.ipynb",
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },