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. js异步请求发展史和yield

    万恶的回调 对前端工程师来说,异步回调是再熟悉不过了,浏览器中的各种交互逻辑都是通过事件回调实现的,前端逻辑越来越复杂,导致回调函数越来越多,同时 nodejs 的流行也让 javascript 在后 ...

  2. python 基础 6.2 raise 关键字使用

    一. raise 关键字    raise 用来触发异常    语法如下:     raise[Exception [,args [,traceback]]]     语句中Exception 是异常 ...

  3. T-SQL简单查询语句(模糊查询)

    T-SQL简单查询语句 简单查询: 1.最简单查询(查所有数据) select * from 表名: 注:* 代表所有列 select * from info 2.查询指定列 select code, ...

  4. 【BZOJ2406】矩阵 二分+有上下界的可行流

    [BZOJ2406]矩阵 Description Input 第一行两个数n.m,表示矩阵的大小. 接下来n行,每行m列,描述矩阵A. 最后一行两个数L,R. Output 第一行,输出最小的答案: ...

  5. 使用T4模板技术

    1.右键->添加->新建项,选择“文本模板” 2.修改代码为: <#@ template debug="false" hostspecific="fal ...

  6. 九度OJ 1034:寻找大富翁 (排序)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5925 解决:2375 题目描述:     浙江桐乡乌镇共有n个人,请找出该镇上的前m个大富翁. 输入:     输入包含多组测试用例.   ...

  7. Kibana + ElasticSearch

    上面一张介绍了ElasticSearch的安装和简单用法. 现在应该都知道ElasticSearch是用来做全文搜索的,那今天我就简单介绍下Kibana. 它是专门用来查看ElasticSearch内 ...

  8. django 设置静态文件,static

    django 设置静态文件,static 一.搜集静态文件 1.1 命令行查看 collectstatic guoguos-MacBook-Pro:mysite guoguo$ python mana ...

  9. MySQL——函数

    MySQL数据库提供了很多函数包括: (1)数学函数 (2)字符串函数 (3)日期和时间函数 (4)条件判断函数 (5)系统信息函数 (6)加密函数 (7)格式化函数 一.数学函数 数学函数主要用于处 ...

  10. python根据圆的参数方程求圆上任意一点的坐标

    from math import cos, sin,pi x0,y0=0,0 r=4.0 angle=-25 x1 = x0 + r * cos(angle * pi / 180) y1 = y0 + ...