sparse matrix format
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的更多相关文章
- 理解Compressed Sparse Column Format (CSC)
最近在看<Spark for Data Science>这本书,阅读到<Machine Learning>这一节的时候被稀疏矩阵的存储格式CSC给弄的晕头转向的.所以专门写一篇 ...
- sparse matrix
w https://en.wikipedia.org/wiki/Sparse_matrix 稀疏矩阵存储格式总结+存储效率对比:COO,CSR,DIA,ELL,HYB - Bin的专栏 - 博客园ht ...
- 311. Sparse Matrix Multiplication
题目: Given two sparse matrices A and B, return the result of AB. You may assume that A's column numbe ...
- 用R的dgCMatrix包来构建稀疏矩阵 | sparse matrix by dgCMatrix
sparse matrix是用来存储大型稀疏矩阵用得,单细胞表达数据基本都用这个格式来存储,因为单细胞很大部分都是0,用普通文本矩阵存储太占空间. 使用也是相当简单: library("Ma ...
- [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 ...
- 稀疏矩阵乘法 · Sparse Matrix Multiplication
[抄题]: 给定两个 稀疏矩阵 A 和 B,返回AB的结果.您可以假设A的列数等于B的行数. [暴力解法]: 时间分析: 空间分析: [思维问题]: [一句话思路]: 如果为零则不相乘,优化常数的复杂 ...
- Sparse Matrix Multiplication
Given two sparse matrices A and B, return the result of AB. You may assume that A's column number is ...
- [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 ...
- [LeetCode] Sparse Matrix Multiplication
Problem Description: Given two sparse matrices A and B, return the result of AB. You may assume that ...
随机推荐
- Hadoop实战-Flume之Sink Load-balancing(十七)
a1.sources = r1 a1.sinks = k1 k2 a1.channels = c1 # Describe/configure the source a1.sources.r1.type ...
- 我的Android进阶之旅------>Android利用Sensor(传感器)实现水平仪功能的小例
这里介绍的水平仪,指的是比较传统的气泡水平仪,在一个透明圆盘内充满液体,液体中留有一个气泡,当一端翘起时,该气泡就会浮向翘起的一端. 利用方向传感器返回的第一个参数,实现了一个指南针小应用. 我 ...
- [java,maven] 使用 maven 来搭建简单的 netty 开发环境
大致过程是: 首先, 使用 mvn 命令在指定路径下面创建一套简单的 java 文件包. 然后, 使用 JIdea 导入 maven 项目的方式将创建好的文件包加载到 IDE 环境中.‘ 接下来, ...
- SAP 增强表MODSAP 和TFDIR
2.第二代增强(基于函数模块的增强),用于SMOD和CMOD 维护 在SAP发布的版本中,使用Call customer-function 'xxx'调用函数模块的, 所以你可以通过在程序中搜索 cu ...
- JS性能优化——加载和执行
JavaScript 在浏览器中的性能,可以认为是开发者所面临得最严重的可用性问题.这个问题因JavaScript的阻塞特性变得复杂, 也就是说当浏览器在执行JavaScript代码时,不能同时做其他 ...
- 《CSS权威指南(第三版)》---第五章 字体
这章主要的内容有: 1.字体:一般使用一种通用的字体. 2.字体加粗:一般从数字100 -900 . 3.字体大小:font-size 4.拉伸和调整字体:font-stretch 5.调整字体大小: ...
- python读取文件后切片
from itertools import islice with open(“1.txt") as f: for a in islice(f,0,2): print(a)
- ios审核过程十大常见被拒问题
欢迎加入ios马甲包经验交流群,群聊号码:744520623 2018年伊始,苹果并没有因为新年的气氛而对CP们“网开一面”.频繁锁榜.调整排名规则以及关键词覆盖算法……不断抛出的大动作,让CP们叫苦 ...
- 联系E-R:学生选课系统
- 常见排序算法-php
1.归并排序 $a = [1, 4, 6, 8, 10, 14, 16]; $b = [2, 3, 5, 8, 9, 11]; function merge_sort($a, $b) { $a_i = ...