NumPy: how to quickly normalize many vectors?

前端 未结 6 981
梦毁少年i
梦毁少年i 2021-01-31 04:47

How can a list of vectors be elegantly normalized, in NumPy?

Here is an example that does not work:

from numpy import *

vectors = array([arange         


        
6条回答
  •  难免孤独
    2021-01-31 05:24

    there is already a function in scikit learn:

    import sklearn.preprocessing as preprocessing
    norm =preprocessing.normalize(m, norm='l2')*
    

    More info at:

    http://scikit-learn.org/stable/modules/preprocessing.html

提交回复
热议问题