Jupyter笔记本错误!内核死了。它将自动重启

问题描述 投票:1回答:1

错误:内核似乎已经死亡。它将自动重启。这特定于几行代码

[当我尝试print(3)时,我在控制台中看到的输出为3,但是当我尝试运行时,以下代码给我一个错误。它运行良好,突然间抛出了这些奇怪的错误。

我尝试重新启动并重新安装和升级所有库,但无济于事。

import numpy as np

versicolor_petal_length = np.array([4.7,  4.5,  4.9,  4.,  4.6,  4.5,  4.7,  3.3,  4.6,  3.9,  3.5,
                                    4.2,  4.,  4.7,  3.6,  4.4,  4.5,  4.1,  4.5,  3.9,  4.8,  4.,
                                    4.9,  4.7,  4.3,  4.4,  4.8,  5.,  4.5,  3.5,  3.8,  3.7,  3.9,
                                    5.1,  4.5,  4.5,  4.7,  4.4,  4.1,  4.,  4.4,  4.6,  4.,  3.3,
                                    4.2,  4.2,  4.2,  4.3,  3.,  4.1])

versicolor_petal_width = np.array([1.4,  1.5,  1.5,  1.3,  1.5,  1.3,  1.6,  1.,  1.3,  1.4,  1.,
                                   1.5,  1.,  1.4,  1.3,  1.4,  1.5,  1.,  1.5,  1.1,  1.8,  1.3,
                                   1.5,  1.2,  1.3,  1.4,  1.4,  1.7,  1.5,  1.,  1.1,  1.,  1.2,
                                   1.6,  1.5,  1.6,  1.5,  1.3,  1.3,  1.3,  1.2,  1.4,  1.2,  1.,
                                   1.3,  1.2,  1.3,  1.3,  1.1,  1.3])


def pearson_r(x, y):
    """Compute Pearson correlation coefficient between two arrays."""
    # Compute correlation matrix: corr_mat
    corr_mat = np.corrcoef(x, y)

    # Return entry [0,1]
    return corr_mat[0, 1]


# Compute Pearson correlation coefficient for I. versicolor: r
r = pearson_r(versicolor_petal_length, versicolor_petal_width)

# Print the result
print(r)

python python-3.x jupyter-notebook anaconda jupyter-console
1个回答
0
投票

出乎意料的是,它是numpy在jupyter笔记本电脑中引起了此类错误。Python已停止在anaconda中工作。

这对我有用:

Upgrading numpy works for me.
pip install -U numpy
© www.soinside.com 2019 - 2024. All rights reserved.