I am trying to add a numpy ndarray to a sparse matrix and I have been unsuccessful in doing so. I was wondering if there is a way to do so, without transforming my sparse matrix into a dense one.
another question is if adding two sparse matrices is possible.
x = np.dot(aSparseMatrix, weights)
y = x + bias
where x is my sparse matrix and bias is the numpy array. The error that I get is currently:
NotImplementedError: adding a scalar to a CSC or CSR matrix is not supported
aSparseMatrix.shape (1, 10063)
weights.shape (10063L, 2L)
bias.shape (2L,)
x.todense()on your spare matrix before adding them together, since the result is not going to have many non-zero items. Or alternatively, if it does, you could turn your dense matrix into sparse format withcsc_matrix(bias)before adding them. It nevertheless looks likebiasis not anndarraybut a scalar, have you tried doingnp.array(bias)before adding them?