sparse-matrix

Efficiently create sparse pivot tables in pandas?

Efficiently create sparse pivot tables in pandas? Question: I’m working turning a list of records with two columns (A and B) into a matrix representation. I have been using the pivot function within pandas, but the result ends up being fairly large. Does pandas support pivoting into a sparse format? I know I can pivot …

Total answers: 4

Get U, Sigma, V* matrix from Truncated SVD in scikit-learn

Get U, Sigma, V* matrix from Truncated SVD in scikit-learn Question: I am using truncated SVD from scikit-learn package. In the definition of SVD, an original matrix A is approxmated as a product A ≈ UΣV* where U and V have orthonormal columns, and Σ is non-negative diagonal. I need to get the U, Σ and …

Total answers: 7

How do I transform a "SciPy sparse matrix" to a "NumPy matrix"?

How do I transform a "SciPy sparse matrix" to a "NumPy matrix"? Question: I am using a python function called “incidence_matrix(G)”, which returns the incident matrix of graph. It is from Networkx package. The problem that I am facing is the return type of this function is “Scipy Sparse Matrix”. I need to have the …

Total answers: 3

Concatenate sparse matrices in Python using SciPy/Numpy

Concatenate sparse matrices in Python using SciPy/Numpy Question: What would be the most efficient way to concatenate sparse matrices in Python using SciPy/Numpy? Here I used the following: >>> np.hstack((X, X2)) array([ <49998×70000 sparse matrix of type ‘<class ‘numpy.float64′>’ with 1135520 stored elements in Compressed Sparse Row format>, <49998×70000 sparse matrix of type ‘<class ‘numpy.int64′>’ …

Total answers: 1

How to compute scipy sparse matrix determinant without turning it to dense?

How to compute scipy sparse matrix determinant without turning it to dense? Question: I am trying to figure out the fastest method to find the determinant of sparse symmetric and real matrices in python. using scipy sparse module but really surprised that there is no determinant function. I am aware I could use LU factorization …

Total answers: 4

Populate a Pandas SparseDataFrame from a SciPy Sparse Matrix

Populate a Pandas SparseDataFrame from a SciPy Sparse Matrix Question: 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() with a scipy.sparse.csc_matrix() or csr_matrix()? Converting to dense format kills RAM badly. Thanks! Asked By: Will …

Total answers: 3

Generating a dense matrix from a sparse matrix in numpy python

Generating a dense matrix from a sparse matrix in numpy python Question: I have a Sqlite database that contains following type of schema: termcount(doc_num, term , count) This table contains terms with their respective counts in the document. like (doc1 , term1 ,12) (doc1, term 22, 2) . . (docn,term1 , 10) This matrix can …

Total answers: 2

Scipy sparse matrices – purpose and usage of different implementations

Scipy sparse matrices – purpose and usage of different implementations Question: Scipy has many different types of sparse matrices available. What are the most important differences between these types, and what is the difference in their intended usage? I’m developing a code in python based on a sample code1 in Matlab. One section of the …

Total answers: 1

Slicing Sparse Matrices in Scipy — Which Types Work Best?

Slicing Sparse Matrices in Scipy — Which Types Work Best? Question: The SciPy Sparse Matrix tutorial is very good — but it actually leaves the section on slicing un(der)developed (still in outline form — see section: “Handling Sparse Matrices”). I will try and update the tutorial, once this question is answered. I have a large …

Total answers: 1