2012-02-13 36 views

回答

8

getrow(i)返回1×n的CSR矩陣,它有一個indices屬性,它給出了相應的值的行指數在data屬性。 (我們知道形狀是1個XN,所以我們沒有對付indptr屬性)。所以這將工作:

row = R.getrow(i) 
max_index = row.indices[row.data.argmax()] if row.nnz else 0 

我們必須處理,其中row.nnz是0分開的情況下,因爲row.data.argmax()如果row.data是一個空數組,則會引發異常。

-1

使用numpy.argmax(或scipy.argmax它是同一回事)

index_of_maximum = scipy.argmax(R.getrow(i).data) 
相關問題