似乎默认csr_matrix
填充缺失值0
。那么如何用 填充缺失值np.nan
呢?
from scipy.sparse import csr_matrix
row = np.array([0, 0, 1, 2, 2, 2])
col = np.array([0, 2, 2, 0, 1, 2])
data = np.array([0, 2, 3, 4, 5, 6])
csr_matrix((data, (row, col)), shape=(3, 3)).toarray()
输出:
array([[0, 0, 2],
[0, 0, 3],
[4, 5, 6]])
预期的:
array([[0, np.nan, 2],
[np.nan, np.nan, 3],
[4, 5, 6]])