python - 属性错误 : module 'numpy' has no attribute 'matlib'

标签 python numpy module

<分区>

我最近开始使用 Python 编写代码。在我的脚本开头,我总是有以下导入:import numpy as np

在我的一个脚本中,我使用了 np.matlib.repmat 函数。它曾经工作正常,但最近它无法运行并显示以下错误:

 AttributeError: module 'numpy' has no attribute 'matlib'

我在 SO 中搜索了这个问题,如果一个人在他的工作目录中有一个名为 numpy.py 的脚本,或者如果安装的版本不同并且不包含调用的模块,那么看起来会出现这样的错误。

我没有将任何文件命名为 numpy.py。我还发现,在我打电话之后:

 from numpy import matlib as mb

我可以使用 mb.repmat。因此,我的 numpy 模块确实包含 matlib 模块。 有人可以提示我,为什么我不能调用 np.matlib

最佳答案

这已经是答案 here .

This is because numpy.matlib is an optional sub-package of numpy that must be imported separately. When you import just numpy without the sub-package matlib, then Python will be looking for .matlib as an attribute of the numpy package. This attribute has not been assigned to numpy without importing numpy.matlib

关于python - 属性错误 : module 'numpy' has no attribute 'matlib' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49926751/

相关文章:

python - py2exe 抛出 ImportError : DLL load failed: The specified module could not be found

python - 使用 groupby 和 mean() 在 Pandas 中保留一个带有分类变量的列

python - 带有 Good Designer for Python 的 GUI 工具包

python - 如何处理巨大的 numpy 数组的计算以避免内存分配错误?

帮助中列出的 Python 模块与 pip 找到的不同

Python:使用 eval 按名称调用类和类方法

python - 如何将多维 h5py 数据集复制到平面一维 Python 列表而不制作任何中间副本?

python - 打包 numpy 数组的更好方法?

module - 如何使用 smarty 模板化 prestashop 模块管理部分

javascript - 我如何获得 Angularjs 模块并在其上调用 .value?