from numpy.random import rand
from sklearn.preprocessing import normalize
from scipy.sparse import csr_matrix
from scipy.linalg import norm
w = (rand(1,10)<0.25)*rand(1,10)
x = (rand(1,10)<0.25)*rand(1,10)
w_csr = csr_matrix(w)
x_csr = csr_matrix(x)
(normalize(w_csr,axis=1,copy=False,norm='l2')*normalize(x_csr,axis=1,copy=False,norm='l2')).todense()
norm(w,ord='fro')*norm(x,ord='fro')
私は scipy csr_matrix を使用しており、フロベニウス ノルムを使用して 2 つの行列を正規化し、それらの積を取得したいと考えています。しかし、scipy.linalg からのノルムと sklearn.preprocessing からの正規化は、行列の評価が異なるようです。技術的には、上記の 2 つのケースでは同じフロベニウス ノルムを計算しているので、2 つの式は同じものに評価されるべきではありませんか? しかし、私は次の答えを得ます:
行列([[ 0.962341]])
0.4431811178371029
それぞれ sklearn.preprocessing と scipy.linalg.norm の場合。私は自分が間違っていることを知ることに本当に興味があります。