Difference between import numpy and import numpy as np

后端 未结 5 615
说谎
说谎 2021-01-31 16:09

I understand that when possible one should use

import numpy as np

This helps keep away any conflict due to namespaces. But I have noticed that

5条回答
  •  长情又很酷
    2021-01-31 17:06

    Well quite an old post but here are my 2 cents over the explanation provided by others.

    numpy (refer git repository) package have various subpackages, f2py is one of them other are as core, ma etc

    If you refer the init.py in numpy package it has imports like -

    from . import core etc 
    

    but it's not having any import for f2py subpackage. That's the reason that a statement like

    import numpy as np
    np.f2py
    

    won't work but

    import numpy as np
    np.core
    

    will work.

提交回复
热议问题