sparse-matrix

Is there an efficient way of concatenating scipy.sparse matrices?

为君一笑 提交于 2019-11-27 04:17:39
问题 I'm working with some rather large sparse matrices (from 5000x5000 to 20000x20000) and need to find an efficient way to concatenate matrices in a flexible way in order to construct a stochastic matrix from separate parts. Right now I'm using the following way to concatenate four matrices, but it's horribly inefficient. Is there any better way to do this that doesn't involve converting to a dense matrix? rmat[0:m1.shape[0],0:m1.shape[1]] = m1 rmat[m1.shape[0]:rmat.shape[0],m1.shape[1]:rmat

How to transform numpy.matrix or array to scipy sparse matrix

坚强是说给别人听的谎言 提交于 2019-11-27 04:10:54
问题 For SciPy sparse matrix, one can use todense() or toarray() to transform to NumPy matrix or array. What are the functions to do the inverse? I searched, but got no idea what keywords should be the right hit. 回答1: You can pass a numpy array or matrix as an argument when initializing a sparse matrix. For a CSR matrix, for example, you can do the following. >>> import numpy as np >>> from scipy import sparse >>> A = np.array([[1,2,0],[0,0,3],[1,0,4]]) >>> B = np.matrix([[1,2,0],[0,0,3],[1,0,4]])

Calculate Euclidean distance matrix using a big.matrix object

Deadly 提交于 2019-11-27 03:38:05
问题 I have an object of class big.matrix in R with dimension 778844 x 2 . The values are all integers (kilometres). My objective is to calculate the Euclidean distance matrix using the big.matrix and have as a result an object of class big.matrix . I would like to know if there is an optimal way of doing that. The reason for my choice of using the class big.matrix is memory limitation. I could transform my big.matrix to an object of class matrix and calculate the Euclidean distance matrix using

Efficient way to solve for X in AX=B in MATLAB when both A and B are big matrices

ぐ巨炮叔叔 提交于 2019-11-27 03:32:27
问题 I have this problem which requires solving for X in AX=B . A is of the order 15000 x 15000 and is sparse and symmetric. B is 15000 X 7500 and is NOT sparse. What is the fastest way to solve for X? I can think of 2 ways. Simplest possible way, X = A\B Using for loop, invA = A\speye(size(A)) for i = 1:size(B,2) X(:,i) = invA*B(:,i); end Is there a better way than the above two? If not, which one is best between the two I mentioned? 回答1: First things first - never, ever compute inverse of A.

How can I create a series of months to join sparse data to?

谁说我不能喝 提交于 2019-11-27 03:00:26
问题 I think this is a pretty common issue, but I don't know what the process is called, so I'll describe it with an example. The concept is that I want to join a sparse dataset to a complete series, such as the days of the week, months of the year, or any ordered set (for example, for ranking). Empty positions in the sparse data will show as NULL alongside the complete series. Let's say I run the following query in SQL Server to find out monthly sales. SELECT YEAR([timestamp]), MONTH([timestamp])

Sparse vs Normal Array Matlab

笑着哭i 提交于 2019-11-27 02:46:19
问题 In Matlab, at what point is having a sparse array better than a normal array if I still have a lot of calculations to do on it, and about 25% of the array are non-zeros? 回答1: Personally, I'd rarely bother with sparse for an array that is only 25% non-zeros. If you don't believe me, try it yourself. A = sprand(2000,2000,0.25); tic,B = A*A;toc Elapsed time is 1.771668 seconds. Af = full(A); tic,B = Af*Af;toc Elapsed time is 0.499045 seconds. The extra work involved with this as a sparse matrix

k-means clustering in R on very large, sparse matrix?

泪湿孤枕 提交于 2019-11-27 01:58:38
问题 I am trying to do some k-means clustering on a very large matrix. The matrix is approximately 500000 rows x 4000 cols yet very sparse (only a couple of "1" values per row). The whole thing does not fit into memory, so I converted it into a sparse ARFF file. But R obviously can't read the sparse ARFF file format. I also have the data as a plain CSV file. Is there any package available in R for loading such sparse matrices efficiently? I'd then use the regular k-means algorithm from the cluster

csv to sparse matrix in python

空扰寡人 提交于 2019-11-27 01:58:28
问题 I have a big csv file which lists connections between nodes in a graph. example: 0001,95784 0001,98743 0002,00082 0002,00091 So this means that node id 0001 is connected to node 95784 and 98743 and so on. I need to read this into a sparse matrix in numpy. How can i do this? I am new to python so tutorials on this would also help. 回答1: Example using lil_matrix (list of list matrix) of scipy. Row-based linked list matrix. This contains a list ( self.rows ) of rows, each of which is a sorted

How expensive is it to compute the eigenvalues of a matrix?

和自甴很熟 提交于 2019-11-27 00:21:57
问题 How expensive is it to compute the eigenvalues of a matrix? What is the complexity of the best algorithms? How long might it take in practice if I have a 1000 x 1000 matrix? I assume it helps if the matrix is sparse? Are there any cases where the eigenvalue computation would not terminate? In R , I can compute the eigenvalues as in the following toy example: m<-matrix( c(13,2, 5,4), ncol=2, nrow=2 ) eigen(m, only.values=1) $values [1] 14 3 Does anyone know what algorithm it uses? Are there

SVD for sparse matrix in R

允我心安 提交于 2019-11-26 21:00:03
问题 I've got a sparse Matrix in R that's apparently too big for me to run as.matrix() on (though it's not super-huge either). The as.matrix() call in question is inside the svd() function, so I'm wondering if anyone knows a different implementation of SVD that doesn't require first converting to a dense matrix. 回答1: The irlba package has a very fast SVD implementation for sparse matrices. 回答2: You can do a very impressive bit of sparse SVD in R using random projection as described in http://arxiv