Why it shows "NameError: name 'histogram' is not defined"?

Why it shows "NameError: name 'histogram' is not defined"?

我正在参加 Coursera 上的课程并在观看教学视频后做作业。

我想知道为什么它在 运行 我自己的代码之后显示 "NameError: name 'histogram' is not defined"。

在您的代码中添加直方图库。请在代码的开头添加行。我应该好好工作了

from histograms import histograms

您需要导入直方图函数,因为 Python 并未内置该函数。有几个不同的包提供直方图——例如 pyplot 和 numpy。这是一个使用 numpy

的例子
import numpy as np

np.histogram([1, 2])

文档:https://numpy.org/doc/1.18/reference/generated/numpy.histogram.html