[Numpy-discussion] Adapting algorithm to accept Scipy sparse matrix
Mon Mar 26 08:26:47 CDT 2007
I want to select/access several columns from a sparse csc_matrix. The only
way I could think of is the following enormously inefficient algorithm which
basically initalizes a new lil_matrix (for assigments) and loops over all
the specified columns and does sparse -> dense -> sparse. All this, to
overcome the inability of using "multi-column" slices in csc_matrices.
def spSelCol(X, A):
"insert doc string"
n = size(X,0)
d = size(A)
X = X.tocsc()
newX = sparse.lil_matrix((d,n))
for i in range(0, d):
# sparse -> dense -> sparse: not good!
newX[i,:] = X[:,A[i]].toarray().flatten()
Is there any way the operation can be made more efficient or should I look
elsewhere (CVXOPT Python toolbox ...)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion