What is csr_matrix.A? [duplicate]

蓝咒 提交于 2019-12-10 22:25:01

问题


I've recently seen something like this:

import numpy as np
row = np.array([0, 0, 1, 2, 2, 2])
col = np.array([0, 2, 2, 0, 1, 2])
data = np.array([1, 2, 3, 4, 5, 6])
from scipy.sparse import csr_matrix
csr_matrix((data, (row, col)), shape=(3, 3)).A

In this case, it returns an numpy array:

array([[1, 0, 2],
       [0, 0, 3],
       [4, 5, 6]], dtype=int64)

This seems to be simply a non-sparse representation of the sparse matrix, but I cannot find it in the csr_matrix docs. Does anybody know for sure what the .A does?


回答1:


the .A is not fromcrs_matrix, it is from numpy:

https://docs.scipy.org/doc/numpy/reference/generated/numpy.matrix.A.html



来源:https://stackoverflow.com/questions/57867223/what-is-csr-matrix-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!