プログラム
参考:
http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.normalize.html
$ cat normal_test.py
from scipy.sparse import lil_matrix, csr_matrix from sklearn.preprocessing import normalize a=lil_matrix((20000,20000)) #quit() f=open("count_wakati_1000_id.txt") h={} h2={} w={} a[1,1]=3 a[1,2]=4 a[1,3]=4 a[2,5]=6 y=normalize(a,norm='l2',axis=1) print a print y quit() #exit() #exit
出力
python normal_test.py
(1, 1) 3.0
(1, 2) 4.0
(1, 3) 4.0
(2, 5) 6.0
(1, 1) 0.468521285666
(1, 2) 0.624695047554
(1, 3) 0.624695047554
(2, 5) 1.0