Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there support for sparse matrices in Python?

Tags:

Is there support for sparse matrices in python?

Possibly in numpy or in scipy?

like image 585
user566621 Avatar asked Jan 07 '11 08:01

user566621


People also ask

How do you store a sparse matrix in python?

Representing a sparse matrix by a 2D array leads to wastage of lots of memory as zeroes in the matrix are of no use in most of the cases. So, instead of storing zeroes with non-zero elements, we only store non-zero elements. This means storing non-zero elements with triples- (Row, Column, value).

Does NumPy have sparse matrices?

Sparse Matrices in PythonA dense matrix stored in a NumPy array can be converted into a sparse matrix using the CSR representation by calling the csr_matrix() function.

Does Sklearn work with sparse matrices?

Sklearn has many algorithms that accept sparse matrices. The way to know is by checking the fit attribute in the documentation.


2 Answers

Yes.

SciPi provides scipy.sparse, a "2-D sparse matrix package for numeric data".

There are seven available sparse matrix types:

  1. csc_matrix: Compressed Sparse Column format
  2. csr_matrix: Compressed Sparse Row format
  3. bsr_matrix: Block Sparse Row format
  4. lil_matrix: List of Lists format
  5. dok_matrix: Dictionary of Keys format
  6. coo_matrix: COOrdinate format (aka IJV, triplet format)
  7. dia_matrix: DIAgonal format
like image 51
Steve Tjoa Avatar answered Oct 01 '22 00:10

Steve Tjoa


  1. CVXOPT - Sparse matrices

  2. Pysparse

like image 29
kros Avatar answered Sep 30 '22 22:09

kros