from numpy import * import operator和import numpy as np

When I was doing the knn algorithm, I saw the different reference methods of unmpy, but I didn't know the difference. Later, after checking the data, I knew the difference between the two, so I made a simple record

Excerpted from  https://zhidao.baidu.com/question/877431035722473172.html


(1) import numpy, if you use numpy attributes, you need to add numpy in front

(2) from numpy import *, you do not need to add numpy

The latter is not recommended. If you refer to the same function as the function in numpy next time, there will be a naming conflict

For example: generate a numpy array [1 2 3 4 5 6 7] from the list [1,2,3,4,5,6,7]

import numpy (to avoid conflicts)

arr = numpy.array([1,2,3,4,5,6,7])

print(arr)

from numpy import * (this method is not recommended)

arr = array([1,2,3,4,5,6,7])

print(arr)