sparse-matrix

How do I get a scipy.csr sparse-matrix as a normal dense matrix without toDense()?

ε祈祈猫儿з 提交于 2019-12-08 14:12:14
问题 I have a problem with sparse matrixes in scipy. I want to use them as a normal matrix but not with todense() function. I m new in this field, I dont know how I can get the same result when I want to multiply the sparse matrix, but without beeing a sparse matrix... I think sparse matrix only used for faster computation, so it should be possible to do this without a sparse matrix: sparse_matrix * 5 == sparase_matrix.todense() * 5 == no_sparse_matrix* 5 data = np.ones(5178) indices = [34,12,545

how to reindex a sparse associative array

ⅰ亾dé卋堺 提交于 2019-12-08 13:01:42
问题 first off, this question is not related to a specific language - I use Haxe to target multiple platforms - so a pseudo code will be more than enough. here's my problem : I have a sparse Matrix description in this form: edges = [ 1,1,2,1,3,1,4,1, 2,2,3,2, 3,3,4,3,5,3, 4,4,5,4,6,4, 5,5,6,5,7,5,25,5,27,5,28,5,29,5,30,5 ]; this describes edges associations: point 1 is linked to points 1, 2, 3 & 4 point 2 is linked to points 2 & 3 point 3 is linked to points 3, 4 & 5 point 4 is linked to points 4,

R: rBind from Matrix package does not work for sparse matrices

北战南征 提交于 2019-12-08 09:12:19
问题 I have the following code: concept_vectors <- foreach(j = 1:2, .combine=rBind, .packages="Matrix") %do% { Matrix::colMeans(sparseX[1:10,],sparseResult=TRUE) } which results in the following error message: Error in { : no method for coercing this S4 class to a vector However, if I either remove 'sparseResult=TRUE' option, or do not use colMeans at all, the code works, even if without colMeans, sparseX is still an S4 object . If I replace rBind with rbind2 directly, then I still see the

How to iterate non-zeroes in a sparse matrix in Chapel

允我心安 提交于 2019-12-08 08:47:38
问题 I have a matrix A still hanging around. It's large, sparse and new symmetric. I've created a sparse domain called spDom that contains the non-zero entries. Now, I want to iterate along row r and find the non-zero entries there, along with the index. My goal is to build another domain that is essentially row r 's non-zeroes. 回答1: Here's an answer that will work with Chapel 1.15 as long as you're willing to store your sparse domain/array in CSR format: First, I'll establish my (small, non

Large SpMat object with RcppArmadillo

浪子不回头ぞ 提交于 2019-12-08 07:24:24
问题 I am trying to learn and use Rcpp and RcppArmadillo for the sparse linear algebra routines. Code below is adaptation of the example here: http://gallery.rcpp.org/articles/armadillo-sparse-matrix/ code <- ' S4 matx(x); IntegerVector Xd = matx.slot("Dim"); IntegerVector Xi = matx.slot("i"); IntegerVector Xp = matx.slot("p"); NumericVector Xx = matx.slot("x"); arma::sp_mat Xsp(Xd[0], Xd[1]); // create space for values, and copy arma::access::rw(Xsp.values) = arma::memory::acquire_chunked<double>

Huge Fourier matrix - MATLAB

与世无争的帅哥 提交于 2019-12-08 07:13:00
问题 I need to create a Fourier matrix in order to apply it to a huge matrix that I needed to define as sparse using spalloc. I tried: F=dftmtx(N); but N is too large so I can't create it. Is there any way to solve this problem? Thank you for your help! 回答1: For each column, you can form a reduced DFT matrix by leaving out the entries that will multiply zeros. Something like X = my_matrix; c = column_index; x = X(:,c); N = length(x); inds = find(x); F = exp( -1j * 2*pi/N * (0:N-1)' * (inds-1) );

Numpy matrix product - sparse matrices

元气小坏坏 提交于 2019-12-08 07:08:55
问题 Let us consider a matrix A as a diagonal matrix and a matrix B a random matrix, both with size N x N. We want to use the sparse properties of the matrix A to optimize the dot product, i.e. dot(B,A). However if we compute the product using the sparcity properties of the matrix A, we cannot see any advantage (and it is much slower). import numpy as np from scipy.sparse import csr_matrix # Matrix sizes N = 1000 #-- matrices generation -- A = np.zeros((N,N), dtype=complex) for i in range(N): A[i]

creating a scipy.lil_matrix using a python generator efficiently

跟風遠走 提交于 2019-12-08 06:01:30
问题 I have a generator that generates single dimension numpy.array s of the same length. I would like to have a sparse matrix containing that data. Rows are generated in the same order I'd like to have them in the final matrix. csr matrix is preferable over lil matrix, but I assume the latter will be easier to build in the scenario I'm describing. Assuming row_gen is a generator yielding numpy.array rows, the following code works as expected. def row_gen(): yield numpy.array([1, 2, 3]) yield

How come pandas pd.SparseDataFrame never completes for large data sets?

大兔子大兔子 提交于 2019-12-08 04:54:46
问题 I have the following python3 code that doesn't seem to complete. Is there an estimate for how long this takes? I would like to be able to use sparsedataframes because a large number of the elements are 0 value. >>> s_matrix <12000x61190 sparse matrix of type '<class 'numpy.float32'>' with 1577553 stored elements in Compressed Sparse Row format> >>> sdf = pd.SparseDataFrame(s_matrix) This has been running for hours and still hasn't completed. Similarly, I was able to load the 1.3GB data set

Sparse matrix slicing memory error

别说谁变了你拦得住时间么 提交于 2019-12-08 04:50:19
问题 I have a sparse matrix csr : <681881x58216 sparse matrix of type '<class 'numpy.int64'>' with 2867209 stored elements in Compressed Sparse Row format> And i want to create a new sparce matrix as a slice of csr : csr_2 = csr[1::2,:] . Problem: When i have csr matrix only, my server's RAM is busy with 40 GB. When i run the csr_2 = csr[1::2,:] , my server's RAM is being dumped completly for 128GB and it falls with "Memory error". 回答1: sparse uses matrix multiplication to select rows like this. I