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 ...
随机推荐
- mac上利用minikube搭建kubernetes(k8s)环境
友情提示:对于初次接触k8s的同学,强烈建议先看看本文最后的参考文章. 环境: mac os(Mojave) 前提:先安装好kubectl (brew install kubectl) .docker ...
- 转载 ----MAC 上搭建lua
MAC 上搭建lua 其实mac上搭建lua环境,google上大把资料,我只是整合一下,因为小弟搭建的时候确实碰到一些问题. 下载和安装lua:(转自这里) 1. 下载最新版的lua-5.2. ...
- Fragment 懒加载
我们在遇到Activity嵌套Fragment的时候经常会遇到多个Fragment页面同时加载数据,一开始的时候就初始化很多页面,有的甚至进入页面的时候,会造成缓慢的现象,下面我们就针对这个问题做一下 ...
- 九度OJ 1176:树查找 (完全二叉树)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5209 解决:2193 题目描述: 有一棵树,输出某一深度的所有节点,有则输出这些节点,无则输出EMPTY.该树是完全二叉树. 输入: 输入 ...
- 【shell】shuf命令,随机排序
shuf命令主要用来对输入的每一行进行随机排序输出,我们可以利用这个属性,实现在几个文件中随机读取一个的功能 如下,zls.txt文件有三行,我们想要随机从中读取一行. 可以看到,每次读取顺序都不一样 ...
- Java for LeetCode 084 Largest Rectangle in Histogram【HARD】
For example, Given height = [2,1,5,6,2,3], return 10. 解题思路: 参考Problem H: Largest Rectangle in a Hist ...
- selenium WebDriverException: Message: unknown error: DevToolsActivePort file doesnt exist
在centos中使用无头chrome报以下错误 selenium.common.exceptions.WebDriverException: Message: unknown error: DevTo ...
- JS的事件流概念*******
事件的概念 HTML中与javascript交互是通过事件驱动来实现的,例如鼠标点击事件.页面的滚动事件onscroll等等,可以向文档或者文档中的元素添加事件侦听器来预订事件. 事件流 事件流描述的 ...
- Java类的加载与生命周期
一.概要: 类的生命周期从类的 加载.连接.初始化 开始,到类的 卸载结束: 二.几个阶段: 加载:查找并加载类的二进制数据.(把类的.class文件的二进制数据读入内存,存放在运行时数据区的方法区: ...
- Mac OS访问Windows共享文件夹
原文地址:http://blog.csdn.net/jinhill/article/details/7246922 最近开始研究Mac OS,遇到的第一个问题就是如何在Mac OS中访问Windows ...