2
기본적으로 간단한 매트릭스 곱셈을 수행하려고합니다. 특히 각 열을 추출하고 길이로 나눠서 정규화합니다.scipy 스파 스 매트릭스를 제자리에 수정하십시오.
#csc sparse matrix
self.__WeightMatrix__ = self.__WeightMatrix__.tocsc()
#iterate through columns
for Col in xrange(self.__WeightMatrix__.shape[1]):
Column = self.__WeightMatrix__[:,Col].data
List = [x**2 for x in Column]
#get the column length
Len = math.sqrt(sum(List))
#here I assumed dot(number,Column) would do a basic scalar product
dot((1/Len),Column)
#now what? how do I update the original column of the matrix, everything that have been returned are copies, which drove me nuts and missed pointers so much
나는 scipy 스파 스 매트릭스 문서를 검색했으며 유용한 정보가 없습니다. 매트릭스의 포인터/참조를 반환하여 함수의 값을 직접 수정할 수있는 함수가 필요했습니다. 감사합니다
'self .__ WeightMatrix __ [:, Col] = ...'를 사용해 보셨습니까? – Blender
나는 원래 값이 변하지 않았기 때문에 [: Col]가 복사본을 반환했으며, 알고있는 한 csc sparse 행렬이 직접 인덱싱을 지원하지 않는 것으로 보이고 오류가 발생하면 그렇게. –