Difference between import numpy and import numpy as np

后端 未结 5 695
说谎
说谎 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 16:55

    numpy.f2py is actually a submodule of numpy, and therefore has to be imported separately from numpy. As aha said before:

    When you do import numpy it creats a link that points to numpy, but numpy is not further linked to f2py. The link is established when you do import numpy.f2py

    when you call the statement import numpy as np, you are shortening the phrase "numpy" to "np" to make your code easier to read. It also helps to avoid namespace issues. (tkinter and ttk are a good example of what can happen when you do have that issue. The UIs look extremely different.)

提交回复
热议问题