I would like to multiply single rows of a csr matrix with a scalar. In numpy I would do
matrix[indices,:] = x * matrix[indices,:]
For csr this raises an exception in scipy.
Is there a way to do this similarily with csr matrixes?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, there’s no way to this directly, because although you can compute
row * x, you can’t assign to a row in a CSR matrix. You can either convert to DOK format and back, or work on the innards of the CSR matrix directly. Thei‘th row of a CSR matrixXis the slicewhich you can update in-place, i.e.
(This obviously works for multiplication and other operations that preserve sparsity, but not things like addition.)