sparse-matrix

Equivalent of rowsum function for Matrix-class (dgCMatrix)

…衆ロ難τιáo~ 提交于 2020-02-23 07:54:08
问题 For the base R matrix class we have the rowsum function, which is very fast for computing column sums across groups of rows. Is there an equivalent function or approach implemented in the Matrix-package? I'm particularly interested in a fast alternative to rowsum for large dgCMatrix-objects (i.e. millions of rows, but roughly 95% sparse). 回答1: I know this is an old question, but Matrix::rowSums might be the function you are looking for. 来源: https://stackoverflow.com/questions/51025979

Special kind of row-by-row multiplication of 2 sparse matrices in Python

被刻印的时光 ゝ 提交于 2020-02-21 13:47:27
问题 What I'm looking for: a way to implement in Python a special multiplication operation for matrices that happen to be in scipy sparse (csr) format. This is a special kind of multiplication, not matrix multiplication nor Kronecker multiplication nor Hadamard aka pointwise multiplication, and does not seem to have any built-in support in scipy.sparse. The desired operation: Each row of the output should contain the results of every product of the elements of the corresponding rows in the two

Special kind of row-by-row multiplication of 2 sparse matrices in Python

十年热恋 提交于 2020-02-21 13:45:04
问题 What I'm looking for: a way to implement in Python a special multiplication operation for matrices that happen to be in scipy sparse (csr) format. This is a special kind of multiplication, not matrix multiplication nor Kronecker multiplication nor Hadamard aka pointwise multiplication, and does not seem to have any built-in support in scipy.sparse. The desired operation: Each row of the output should contain the results of every product of the elements of the corresponding rows in the two

Understand the csr format

 ̄綄美尐妖づ 提交于 2020-02-05 06:06:06
问题 I am trying to undersand how scipy CSR works. https://docs.scipy.org/doc/scipy/reference/sparse.html For example, of the following matrix on https://en.wikipedia.org/wiki/Sparse_matrix ( 0 0 0 0 ) ( 5 8 0 0 ) ( 0 0 3 0 ) ( 0 6 0 0 ) it says the CSR representation is the following. Must V list one row after another with non-zero elements in a row list from left to right? I can understand COL_INDEX is the column index (column 1 is indexed as 0) corresponding to elements in V. I don't understand

putting column into empty sparse matrix

江枫思渺然 提交于 2020-02-03 00:05:24
问题 I want to put a column from one sparse columnar matrix into another (empty) sparse columnar matrix. Toy code: import numpy as np import scipy.sparse row = np.array([0, 2, 0, 1, 2]) col = np.array([0, 0, 2, 2, 2]) data = np.array([1, 2, 4, 5, 6]) M=scipy.sparse.csc_matrix((data, (row, col)), shape=(3, 3)) E=scipy.sparse.csc_matrix((3, 3)) #empty 3x3 sparse matrix E[:,1]=M[:,0] However I get the warning: SparseEfficiencyWarning: Changing the sparsity structure of a csc_matrix is >expensive. lil

Extraction speed in Matrix package is very slow compared to regular matrix class

≡放荡痞女 提交于 2020-01-29 22:21:26
问题 This is an example of comparing row extraction from large matrices, sparse and dense, using the Matrix package versus the regular R base-matrix class. For dense matrices the speed is almost 395 times faster for the base class matrix : library(Matrix) library(microbenchmark) ## row extraction in dense matrices D1<-matrix(rnorm(2000^2), 2000, 2000) D2<-Matrix(D1) > microbenchmark(D1[1,], D2[1,]) Unit: microseconds expr min lq mean median uq max neval D1[1, ] 14.437 15.9205 31.72903 31.4835 46

Extraction speed in Matrix package is very slow compared to regular matrix class

笑着哭i 提交于 2020-01-29 22:19:40
问题 This is an example of comparing row extraction from large matrices, sparse and dense, using the Matrix package versus the regular R base-matrix class. For dense matrices the speed is almost 395 times faster for the base class matrix : library(Matrix) library(microbenchmark) ## row extraction in dense matrices D1<-matrix(rnorm(2000^2), 2000, 2000) D2<-Matrix(D1) > microbenchmark(D1[1,], D2[1,]) Unit: microseconds expr min lq mean median uq max neval D1[1, ] 14.437 15.9205 31.72903 31.4835 46

Extraction speed in Matrix package is very slow compared to regular matrix class

久未见 提交于 2020-01-29 22:19:27
问题 This is an example of comparing row extraction from large matrices, sparse and dense, using the Matrix package versus the regular R base-matrix class. For dense matrices the speed is almost 395 times faster for the base class matrix : library(Matrix) library(microbenchmark) ## row extraction in dense matrices D1<-matrix(rnorm(2000^2), 2000, 2000) D2<-Matrix(D1) > microbenchmark(D1[1,], D2[1,]) Unit: microseconds expr min lq mean median uq max neval D1[1, ] 14.437 15.9205 31.72903 31.4835 46

Extraction speed in Matrix package is very slow compared to regular matrix class

*爱你&永不变心* 提交于 2020-01-29 22:18:37
问题 This is an example of comparing row extraction from large matrices, sparse and dense, using the Matrix package versus the regular R base-matrix class. For dense matrices the speed is almost 395 times faster for the base class matrix : library(Matrix) library(microbenchmark) ## row extraction in dense matrices D1<-matrix(rnorm(2000^2), 2000, 2000) D2<-Matrix(D1) > microbenchmark(D1[1,], D2[1,]) Unit: microseconds expr min lq mean median uq max neval D1[1, ] 14.437 15.9205 31.72903 31.4835 46

sparse matrix svd in python

扶醉桌前 提交于 2020-01-29 02:32:05
问题 Does anyone know how to perform svd operation on a sparse matrix in python? It seems that there is no such functionality provided in scipy.sparse.linalg. 回答1: You can use the Divisi library to accomplish this; from the home page: It is a library written in Python, using a C library (SVDLIBC) to perform the sparse SVD operation using the Lanczos algorithm. Other mathematical computations are performed by NumPy. 回答2: Sounds like sparsesvd is what you're looking for! SVDLIBC efficiently wrapped