import numpy as np 和 from numpy import pi的区别(转载自stack Overflow)
as keyword allows you to use shorthands and rename stuff. Particularly useful when you have long names or use things from that module a lot. In numpy you use a lot of stuff from it, so it’s certainly better to write np. than numpy. when there’s a lot of such calls, isn’t it?
from … import is just a way of importing only some components. If you use that lib a lot in your code, you do import . If you need only some elements and names don’t clash with yours, you do from import ,
Important: from … import still allows as notation! They are not counterparts. My fav shorthand is from pprint import pprint as pp when debugging in the console.
原链接:https://stackoverflow.com/questions/57889937/what-is-the-difference-between-import-numpy-as-np-and-from-numpy-import-array