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 2013-03-04 07:09:12
我這樣認爲,原始值並沒有改變,導致我相信[:Col]返回了一個副本,並且據我所知,似乎csc稀疏矩陣不支持直接索引,如果發生錯誤這樣做。 – 2013-03-04 07:10:10