How do I transform a “SciPy sparse matrix” to a “NumPy matrix”?

前端 未结 3 1016
情书的邮戳
情书的邮戳 2021-01-03 22:34

I am using a python function called \"incidence_matrix(G)\", which returns the incident matrix of graph. It is from Networkx package. The problem that I am facing is the ret

3条回答
  •  礼貌的吻别
    2021-01-03 22:45

    I found that in the case of csr matrices, todense() and toarray() simply wrapped the tuples rather than producing a ndarray formatted version of the data in matrix form. This was unusable for the skmultilearn classifiers I'm training.

    I translated it to a lil matrix- a format numpy can parse accurately, and then ran toarray() on that:

    sparse.lil_matrix().toarray()
    

提交回复
热议问题