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. android 导入项目 项目中文字乱码问题

    乱码问题出现了几次,一直没有在意,今天又出现了,现总结如下: eclipse之所以会出现乱码问题是因为eclipse编辑器选择的编码规则是可变的.一般默认都是UTF-8或者GBK,当从外部导入的一个工 ...

  2. jqPaginator-master | kkpager-master 这两个分页插件的使用方法

    首先:百度"分页插件" 就会 找到这条链接: url=X8P3UpOM-6ceSfjdngX0oh9cNmVwSDy94CxKqWIazhyZ7If4S8wgpPqyEGUhk2t ...

  3. N皇后问题算法

    N皇后问题的两种主要算法是试探回溯法和位运算法.前一种是经典算法,后一种是目前公认的最高效算法,后者比前者效率提高了至少一个数量级.很多问题可以借鉴位运算的思想. 以下是转载的我认为写的比较好的一篇N ...

  4. NFT是什么,有什么前景?

    去年 11 月,Crypokitties 的发布给加密货币的世界带来了风暴,有些加密猫的价格甚至涨到了 30 万美元,以太坊网络拥堵不堪,平均贡献了当时以太坊网络30%的交易额.当 Cryptokit ...

  5. SAP RFC 的介绍

    第一部分 RFC技术 什么是RFC? RFC是SAP系统和其他(SAP或非SAP)系统间的一个重要而常用的双向接口技术,也被视为SAP与外部通信的基本协议.简单地说,RFC过程就是系统调用当前系统外的 ...

  6. JDK动态proxy原理解析

    转: 之前虽然会用JDK的动态代理,但是有些问题却一直没有搞明白.比如说:InvocationHandler的invoke方法是由谁来调用的,代理对象是怎么生成的,直到前几个星期才把这些问题全部搞明白 ...

  7. API的理解和使用——哈希类型的命令

    哈希常用的命令复习 命令 功能 hset key field value 设置哈希值 hsetnx 设置哈希值,field或键必须不存在 hget 获取某个file对应的值 hdel 删除一个或多个f ...

  8. DOM相关操作的案例

    1 . 模态框案例 示例 :  打开网页时有一个普通的按钮,点击当前按钮显示一个背景图,中心并弹出一个弹出框,点击X的时候会关闭当前的模态框 <!DOCTYPE html> <htm ...

  9. PAT 甲级 1007. Maximum Subsequence Sum (25) 【最大子串和】

    题目链接 https://www.patest.cn/contests/pat-a-practise/1007 思路 最大子列和 就是 一直往后加 如果 sum < 0 就重置为 0 然后每次 ...

  10. 2 《锋利的jQuery》jQuery选择器

    tip1:jquery检查某个元素是否存在:if($("#tt").length>0){}或者if($("#tt")[0]){} 先说css选择器有: 标 ...