see Spare Matrix wikipedia item,
and scipy's documentation on different choices of sparse matrix type

sparse matrix storage, only store non-zero entries. there're multiple possible data structures for this, and can be divided into 2 groups

  • support efficient modification

    • DOK (dictory of keys)
    • LIL (list of lists)
    • COO (coordiate list)
  • support efficient access
    • CSR/CSC (compressed sparse row/column)

Dictionary of Keys (DOK)

  • a dictionary that maps (row, col)-pair to the value;
  • good for incremental build;
  • poor for iterating;
  • often used for building matrix, and convert to another format

List of Lists (LIL)

  • matrix is a list of lists, one list for each row;
  • each row list stores the (col, val) pair list;
  • efficient for creation/insertion

Coordinate List (COO) aka IJV format

  • sotre a list of (row, col, value) triplets, and ideally sorted by row then col;
  • also known as IJV or Triplet format.

Compressed Sparse Row (CSR)

  • an m*n matrix is represented as 3 vectors: vals, row_ptr, col_idx;
  • vals: all values in row-major; length is number of non-zero matrix elements;
  • col_idx: all values' column index in row-major order; same length with vals;
  • row_ptr: row_ptr[0] = 0, row_ptr[k] = number-of-vals in first k rows; i.e. row_ptr[k+1]-row_ptr[k] is number of elements at row k;
  • this is extremely optimized for row-by-row iteration: only access current portion of vals and col_idx, and 2 elements of row_ptr to determine the portion - super cache friendly;
  • thus very suitable for cases like matrix-multiplication, matrix-vector-multiplication;

sparse matrix format的更多相关文章

  1. 理解Compressed Sparse Column Format (CSC)

    最近在看<Spark for Data Science>这本书,阅读到<Machine Learning>这一节的时候被稀疏矩阵的存储格式CSC给弄的晕头转向的.所以专门写一篇 ...

  2. sparse matrix

    w https://en.wikipedia.org/wiki/Sparse_matrix 稀疏矩阵存储格式总结+存储效率对比:COO,CSR,DIA,ELL,HYB - Bin的专栏 - 博客园ht ...

  3. 311. Sparse Matrix Multiplication

    题目: Given two sparse matrices A and B, return the result of AB. You may assume that A's column numbe ...

  4. 用R的dgCMatrix包来构建稀疏矩阵 | sparse matrix by dgCMatrix

    sparse matrix是用来存储大型稀疏矩阵用得,单细胞表达数据基本都用这个格式来存储,因为单细胞很大部分都是0,用普通文本矩阵存储太占空间. 使用也是相当简单: library("Ma ...

  5. [leetcode]311. Sparse Matrix Multiplication 稀疏矩阵相乘

    Given two sparse matrices A and B, return the result of AB. You may assume that A's column number is ...

  6. 稀疏矩阵乘法 · Sparse Matrix Multiplication

    [抄题]: 给定两个 稀疏矩阵 A 和 B,返回AB的结果.您可以假设A的列数等于B的行数. [暴力解法]: 时间分析: 空间分析: [思维问题]: [一句话思路]: 如果为零则不相乘,优化常数的复杂 ...

  7. Sparse Matrix Multiplication

    Given two sparse matrices A and B, return the result of AB. You may assume that A's column number is ...

  8. [LeetCode] Sparse Matrix Multiplication 稀疏矩阵相乘

    Given two sparse matrices A and B, return the result of AB. You may assume that A's column number is ...

  9. [LeetCode] Sparse Matrix Multiplication

    Problem Description: Given two sparse matrices A and B, return the result of AB. You may assume that ...

随机推荐

  1. C# C/S程序使用HTML文件作为打印模板

    C#   C/S程序使用HTML文件作为打印模板 在网上找了一堆的资料,整理到郁闷呀,慢慢试慢慢改.哎,最终成功了,哈,菜鸟伤不起呀 public partial class Print : Form ...

  2. iOS判断为空或者只为空格

    本文转载至 :http://www.cnblogs.com/superhappy/archive/2012/11/08/2761403.html 经常有需求 要判断不能为空,后台老是鄙视不做非空判断的 ...

  3. Flask,ORM及模板引擎Jinja2

    跨域:http://blog.csdn.net/yannanxiu/article/details/53036508 下载flask_cors包 pip install flask-cors 使用fl ...

  4. SAM4E单片机之旅——13、LCD之ASF初步

    在Atmel Studio 6中,集成了Atmel Software Framework(ASF框架).通过它提供的库,可以很快速地完成新的项目. 这次的最终目标使用ASF在LCD上显示出文字“Hel ...

  5. ridge regression 无惩罚,导致预测结果空间过大而无实用价值

    [ biased regression methods to reduce variance---通过偏回归来减小方差] https://onlinecourses.science.psu.edu/s ...

  6. JavaScript演示如何访问Search字段

    <!DOCTYPE html> <html> <body> <h3>演示如何访问Search字段</h3> <input type=& ...

  7. SAP采购寄售业务操作步骤

    [转自 http://blog.sina.com.cn/s/blog_6466e5f70100jghg.html] 这里所示的是比较完整的步骤,包含了:信息记录.采购合同.货源清单.采购申请.采购订单 ...

  8. display:inline

    一.基本介绍 它可以让行内显示为块的元素,变为行内显示,例如 <div> DIV1 </div> <div> DIV2 </div> 这里DIV1和DI ...

  9. mysql忘记root密码或报错:ERROR 1044 (42000): Access denied for user ”@’localhost’ to database ‘xx‘

    有的时候忘记了root密码或其他用户的密码,登录的时候报错:ERROR 1044 (42000): Access denied for user ”@’localhost’ to database ' ...

  10. CentOS下配置静态IP

    第一.在VMware中进行配置使用桥接的方式.点击编辑选择虚拟网络编辑器 选择桥接模式,选择桥接到外部的网卡.选择我们主机下的网卡 第二步.配置虚拟机使用桥接模式 第三步:启动虚拟机进入到 /etc/ ...