我在ubuntu 16.04
上使用ubuntu 16.04
。正如下面的代码所描述的,我不能使用来自np.matlib
的任何函数,但是在导入之后,就可以使用它了。有什么办法解决这个问题吗?提前感谢!
$ python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> a = np.matlib.repmat([1,1],1,2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'matlib'
>>> import numpy.matlib as npm
>>> a = npm.repmat([1,1],1,2)
>>> print a
[[1 1 1 1]]
>>>
我认为这是库冲突,如果是的话,我如何知道哪一种冲突与哪一种冲突?
发布于 2018-03-07 02:55:43
Python导入系统在导入包时不会自动加载包的子模块。NumPy的__init__.py
会自动在普通import numpy
上加载大多数NumPy子模块,但不包括numpy.matlib
。
在程序中的某些代码显式导入numpy.matlib
之前,numpy.matlib
将不存在,其内容也无法访问。
https://stackoverflow.com/questions/49143198
复制相似问题