问题
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 from
crs_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