[SciPy-dev] sparse deletion and sparse random matrices.
Wed Apr 16 13:16:52 CDT 2008
Thanks to all the help I got on this list, I have been able to figure
out how to get a bunch of our code working with sparse matrices in
The two things I believe could be immediately useful are some simple
routines for deleting rows and columns, and routines to create sparse
random matrices. The latter would be greatly useful for examples,
exploration, debugging etc.
The routines might look something like below. If there's interest, I
can help with whatever needs to be done to put them in the tree:
# sparse random matrices..
def sprand (self, m, n, density):
nnz = m*n*density
ij = fix(nnz*rand(2, nnz))
data = rand(nnz)
s = sparse.coo_matrix((data, ij), shape=(m, n))
# Deletion. Performance should be comparable to native code..
def deleterowcol(self, A, delrow, delcol):
A = A.tocsc()
m = A.shape
n = A.shape
keep = delete (arange(0, m), delrow)
A = A[keep, :]
keep = delete (arange(0, m), delcol)
A = A[:, keep]
More information about the Scipy-dev