Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我说时import numpy as np,我可以从 np 访问 numpy 中的所有模块和子模块。我不必说np.matrixlib.matrix。这个功能叫什么?如何在我的包中实现这一点。
import numpy as np
np.matrixlib.matrix
如果想要子模块在主模块中可用,则必须将它们导入__init__.py.
__init__.py
参见例如numpy/__init__.py:
numpy/__init__.py
from .matrixlib import *
numpy.matrixlib将所有内容从numpy.
numpy.matrixlib
numpy
我认为你的意思是:
from numpy import *
虽然我觉得这可能只做第一层的功能。您可能需要另一个用于“更深入”的功能:
from numpy.matrixlib import matrix