sparse-matrix

Pandas : saving Series of dictionaries to disk

匆匆过客 提交于 2019-12-13 14:14:06
问题 I have a python pandas Series of dictionaries : id dicts 1 {'5': 1, '8': 20, '1800': 2} 2 {'2': 2, '8': 1, '1000': 25, '1651': 1} ... ... ... ... ... ... 20000000 {'2': 1, '10': 20} The (key, value) in the dictionaries represent ('feature', count). About 2000 unique features exist. The Series' memory usage in pandas is about 500MB. What would be the best way to write this object to disk (having ideally low disk space usage, and being fast to write and fast to read back in afterwards) ?

What is a fast simple solver for a large Laplacian matrix?

[亡魂溺海] 提交于 2019-12-13 13:22:38
问题 I need to solve some large (N~1e6) Laplacian matrices that arise in the study of resistor networks. The rest of the network analysis is being handled with boost graph and I would like to stay in C++ if possible. I know there are lots and lots of C++ matrix libraries but no one seems to be a clear leader in speed or usability. Also, the many questions on the subject, here and elsewhere seem to rapidly devolve into laundry lists which are of limited utility. In an attempt to help myself and

Translate matlab code to python (scipy)

匆匆过客 提交于 2019-12-13 12:34:14
问题 I' trying to translate this matlab code to python: T = length(z); lambda = 10; I = speye(T) D2 = spdiags(ones(T-2,1)*[1 -2 1],[0:2],T-2,T); z_stat = (I-inv(I + lambda^2*D2'*D2))*z; What I got at the moment: T = len(signal) lam = 10; I = np.identity(T) D2 = scipy.sparse.spdiags(np.ones((T-2,1),dtype=np.int)*[1,-2,1],(range(0,3)),T-2,T); At the moment I get this error "scipy.sparse.sp...ge(0,3)),T-2,T)" ValueError: number of diagonals (298) does not match the number of offsets (3) args tuple: (

How can do I make a sparse matrix using cell arrays in MATLAB?

冷暖自知 提交于 2019-12-13 09:20:47
问题 A sparse matrix is a large matrix with almost all elements of the same value (typically zero). The normal representation of a sparse matrix takes up lots of memory when the useful information can be captured with much less. A possible way to represent a sparse matrix is with a cell vector whose first element is a 2-element vector representing the size of the sparse matrix. The second element is a scalar specifying the default value of the sparse matrix. Each successive element of the cell

Create sparse matrix from tweets

痴心易碎 提交于 2019-12-13 07:31:46
问题 I have some tweets and other variables that I would like to convert into a sparse matrix. This is basically what my data looks like. Right now it is saved in a data.table with one column that contains the tweet and one column that contains the score. Tweet Score Sample Tweet :) 1 Different Tweet 0 I would like to convert this into a matrix that looks like this: Score Sample Tweet Different :) 1 1 1 0 1 0 0 1 1 0 Where there is one row in the sparse matrix for each row in my data.table. Is

Scipy sparse matrix assignment using only stored elements

爱⌒轻易说出口 提交于 2019-12-13 07:15:32
问题 I have a large sparse matrix globalGrid (lil_matrix) and a smaller matrix localGrid (coo_matrix). The localGrid represents a subset of the globalGrid and I want to update the globalGrid with the localGrid. For this I use the following code (in Python Scipy): globalGrid[xLocalgrid:xLocalgrid + localGrid.shape[0], yLocalgrid: yLocalgrid + localGrid.shape[1]] = localGrid where xLocalGrid and yLocalGrid are the offset of the localGrid origin with respect to the globalGrid. The problem is that the

Parallel array or array of structures [closed]

风格不统一 提交于 2019-12-13 07:09:11
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I am trying to implement a sparse matrix (COO format) framework in C for parallel computing (shared memory). Initially I was planning to have an array of struct of the spatial information. typedef struct {

Determining a sparse matrix quotient

不羁的心 提交于 2019-12-13 07:03:18
问题 I am looking to divide two sparce matricies in python 2.7, essentially k = numerator / denominator , with the result as a sparse matrix of type sp.csr_matrix . I am using scipy as sp and numpy as np . To do this, I am following linear format of taking the dot product of numerator and inverse of denominator. Both items are of format sp.csr_matrix(([],([],[])),shape=[R,R]) . The calculation for k itself is k = sp.csr_matrix(numerator.dot(sp.linalg.inv(denominator))) Doing this returns the

Permuting sparse matrices in Eigen

假装没事ソ 提交于 2019-12-13 04:52:28
问题 I want to permute the rows and columns of a sparse matrix in Eigen. Here's the code I have but it's not working. #include <iostream> #include <Eigen/Core> #include <Eigen/SparseCore> typedef Eigen::SparseMatrix<double> SpMat; using namespace Eigen; using namespace std; int myrandom (int i) { return std::rand()%i;} int main() { PermutationMatrix<Dynamic,Dynamic> perm(5); MatrixXd x = MatrixXd::Random(5,5); SpMat y = x.sparseView(); int dim=5; perm.setIdentity(); for (int i=dim-1; i>0; --i) {

finding eigenvalues of huge and very sparse matrix

删除回忆录丶 提交于 2019-12-13 04:24:27
问题 I have the following problem. There is a matrix A of size NxN , where N = 200 000 . It is very sparse, there are exactly M elements in each row, where M={6, 18, 40, 68, 102} (I have 5 different scenarios), the rest are zeros. Now I would like to get all the eigenvalues and eigenvectors of matrix A . Problem is, I cannot put matrix A into memory as it is around 160 GB of data. What I am looking for is a software that allows nice storing of sparse matrix (without zeros, my matrix is just few MB