I would like to use scipy.spatial.distance.cosine
in my code. I can import the spatial
submodule if I do something like import scipy.spatial
or from scipy import spatial
, but if I simply import scipy
calling scipy.spatial.distance.cosine(...)
results in the following error: AttributeError: 'module' object has no attribute 'spatial'
.
What is wrong with the second approach?
scipy
in particular, the reason that we do not import all subpackages is that there are a lot of them and many have large extension modules that consume quite a bit of time to load. Most programs don't need all of scipy loaded, so that would add a lot of extra overhead to all programs if we always imported all subpackages. – Mutiny