sparse-matrix

Populate a Pandas SparseDataFrame from a SciPy Sparse Coo Matrix

会有一股神秘感。 提交于 2020-01-10 05:19:06
问题 (This question relates to "populate a Pandas SparseDataFrame from a SciPy Sparse Matrix". I want to populate a SparseDataFrame from a scipy.sparse. coo _matrix (specifically) The mentioned question is for a different SciPy Sparse Matrix ( csr )... So here it goes...) I noticed Pandas now has support for Sparse Matrices and Arrays. Currently, I create DataFrame() s like this: return DataFrame(matrix.toarray(), columns=features, index=observations) Is there a way to create a SparseDataFrame()

Iterating through a scipy.sparse vector (or matrix)

女生的网名这么多〃 提交于 2020-01-09 03:01:06
问题 I'm wondering what the best way is to iterate nonzero entries of sparse matrices with scipy.sparse. For example, if I do the following: from scipy.sparse import lil_matrix x = lil_matrix( (20,1) ) x[13,0] = 1 x[15,0] = 2 c = 0 for i in x: print c, i c = c+1 the output is 0 1 2 3 4 5 6 7 8 9 10 11 12 13 (0, 0) 1.0 14 15 (0, 0) 2.0 16 17 18 19 so it appears the iterator is touching every element, not just the nonzero entries. I've had a look at the API http://docs.scipy.org/doc/scipy/reference

solving a sparse non linear system of equations using scipy.optimize.root

一曲冷凌霜 提交于 2020-01-07 06:41:55
问题 I want to solve the following non-linear system of equations. Notes the dot between a_k and x represents dot product . the 0 in the first equation represents 0 vector and 0 in the second equation is scaler 0 all the matrices are sparse if that matters. Known K is an n x n (positive definite) matrix each A_k is a known (symmetric) matrix each a_k is a known n x 1 vector N is known (let's say N = 50). But I need a method where I can easily change N. Unknown (trying to solve for) x is an n x 1 a

solving a sparse non linear system of equations using scipy.optimize.root

◇◆丶佛笑我妖孽 提交于 2020-01-07 06:41:49
问题 I want to solve the following non-linear system of equations. Notes the dot between a_k and x represents dot product . the 0 in the first equation represents 0 vector and 0 in the second equation is scaler 0 all the matrices are sparse if that matters. Known K is an n x n (positive definite) matrix each A_k is a known (symmetric) matrix each a_k is a known n x 1 vector N is known (let's say N = 50). But I need a method where I can easily change N. Unknown (trying to solve for) x is an n x 1 a

Dot product between scipy sparse matrix and numpy array give ValueError

会有一股神秘感。 提交于 2020-01-06 06:43:21
问题 I'm trying to calculate the dot product between a scipy parse matrix and a numpy array. First I was using a numpy matrix, which you can see in the following code: def power_iteration(matrix, n): b_k = np.random.rand(matrix.shape[1]) for _ in range(n): b_k = np.dot(matrix, b_k) return b_k Here the matrix is a numpy matrix and no error occurs. If you pass a scipy sparse matrix as a parameter, the following error occurs: ValueError: shapes (6762,6762) and (1,6762) not aligned: 6762 (dim 1) != 1

Resolve matrix differential equation with sparse matrix and ojAlgo

ぐ巨炮叔叔 提交于 2020-01-06 06:42:28
问题 I am developping a java evolution tool with ojAlgo, and I try to resolve the following equation : where A is a sparse matrix (for now the dimension of the matrix is 2000 x 2000, it will be scaled later on), A is not symmetric and use only real values. I made some researchs and I tried to find the way to resolve this equation (using SparseStore) on github wiki/javadoc but I didn't find a way to do it. Can you help me find methods/class I should use ? Thank you 回答1: There is no direct/specific

Dot product between scipy sparse matrix and numpy array give ValueError

孤街醉人 提交于 2020-01-06 06:42:05
问题 I'm trying to calculate the dot product between a scipy parse matrix and a numpy array. First I was using a numpy matrix, which you can see in the following code: def power_iteration(matrix, n): b_k = np.random.rand(matrix.shape[1]) for _ in range(n): b_k = np.dot(matrix, b_k) return b_k Here the matrix is a numpy matrix and no error occurs. If you pass a scipy sparse matrix as a parameter, the following error occurs: ValueError: shapes (6762,6762) and (1,6762) not aligned: 6762 (dim 1) != 1

Sparse Storage in Fortran: Only Reading and Writing

孤人 提交于 2020-01-06 06:02:48
问题 I have an array with multiple dimensions (the goal is to allow for about 100) and each dimension has a size of about 2^10 and I only need to store in it about 1000 double precision coefficients. I don't need to do any operation with this array aside from reading and writing into it. The code is written in Fortran 90. I assume that if I a library like one of the ones mentioned in this answer I would be able to store the do this, but would this be optimized for the simple reading and writing

Concatenate dfm matrices in 'quanteda' package

∥☆過路亽.° 提交于 2020-01-06 03:06:51
问题 Does there exist a method to concatenate two dfm matrices containing different numbers of columns and rows at the same time? It can be done with some additional coding, so I am not interested in an adhoc code but in the general and elegant solution if there exists any. An example: dfm1 <- dfm(c(doc1 = "This is one sample text sample."), verbose = FALSE) dfm2 <- dfm(c(doc2 = "Surprise! This is one sample text sample."), verbose = FALSE) rbind(dfm1, dfm2) gives an error. The 'tm' package can

bind together sparse model matrices by row names

六眼飞鱼酱① 提交于 2020-01-06 01:30:15
问题 I am trying to construct a large sparse matrix with a split-apply-combine approach by separately calling sparse.model.matrix() from the package Matrix on subsets of columns of a dataframe and then binding them together into a full matrix. I have to do this because of memory limitations (I can't call sparse.model.matrix on the whole df at once). This process works fine, and I get a list of sparse matrices, but these have different dimensions and when I try to bind them together, I can't. ex: