[Numpy-discussion] Adapting algorithm to accept Scipy sparse matrix
Wed Mar 21 14:47:15 CDT 2007
Alright, may all the trickery rest until that day.
One thing I need to do however is patch a column of "ones" onto a sparse
matrix of format n * d with n >> d. I tried "concatenate" and it didn't work
so I did like this:
"insert doc string"
n, d = shape(X)
X = X.tocsc()
newX = sparse.lil_matrix((d + 1,n))
newX[0,:] = ones(n)
for i in range(1, d + 1):
newX[i,:] = X[:,i - 1].toarray().flatten()
It basically, blows each column in the old matrix to dense format and
assigns it to a row in a new matrix which already contains an extra row of
ones. In the end I transpose. Is there a simpler and more efficient
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion