How to access sparse matrix elements?

前端 未结 4 1879
情歌与酒
情歌与酒 2021-01-31 02:07
type(A)

A.shape
(8529, 60877)
print A[0,:]
  (0, 25)   1.0
  (0, 7422) 1.0
  (0, 26062)    1.0
  (0, 31804)    1.0
  (0, 41         


        
4条回答
  •  忘掉有多难
    2021-01-31 02:19

    If it is for calculating TFIDF score using TfidfTransformer, yu can get the IDF by tfidf.idf_. Then the sparse array name, say 'a', a.toarray().

    toarray returns an ndarray; todense returns a matrix. If you want a matrix, use todense; otherwise, use toarray.

提交回复
热议问题