我有一个MxN稀疏csr_matrix,我想在矩阵的右边添加一些只有零的列.原则上,阵列indptr,indices并data保持相同的,所以我只是想改变矩阵的尺寸.但是,这似乎没有实现.
>>> A = csr_matrix(np.identity(5), dtype = int)
>>> A.toarray()
array([[1, 0, 0, 0, 0],
[0, 1, 0, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 0],
[0, 0, 0, 0, 1]])
>>> A.shape
(5, 5)
>>> A.shape = ((5,7))
NotImplementedError: Reshaping not implemented for csr_matrix.
Run Code Online (Sandbox Code Playgroud)
水平堆叠零矩阵似乎也不起作用.
>>> B = csr_matrix(np.zeros([5,2]), dtype = int)
>>> B.toarray()
array([[0, 0],
[0, 0],
[0, 0],
[0, 0],
[0, 0]])
>>> np.hstack((A,B))
array([ …Run Code Online (Sandbox Code Playgroud)