scipy.sparse中csr.matrix的用法

作用:用于压缩稀疏行矩阵

1、csr_matrix(D) with a dense matrix or rank-2 ndarray D

2、csr_matrix(S) with another sparse matrix S (equivalent to S.tocsr())

3、csr_matrix((M, N), [dtype]) to construct an empty matrix with shape (M, N) dtype is optional, defaulting to dtype=‘d’.

>>> import numpy as np
>>> from scipy.sparse import csr_matrix
>>> csr_matrix((3, 4), dtype=np.int8).toarray()
array([[0, 0, 0, 0],[0, 0, 0, 0],[0, 0, 0, 0]], dtype=int8)

4、csr_matrix((data, (row_ind, col_ind)), [shape=(M, N)]) where data, row_ind and col_ind satisfy the relationship a[row_ind[k], col_ind[k]] = data[k].

>>> row = np.array([0, 0, 1, 2, 2, 2])
>>> col = np.array([0, 2, 2, 0, 1, 2])
>>> data = np.array([1, 2, 3, 4, 5, 6])>>> csr_matrix((data, (row, col)), shape=(3, 3)).toarray()
array([[1, 0, 2],[0, 0, 3],[4, 5, 6]])Duplicate entries are summed together:
>>> row = np.array([0, 1, 2, 0])
>>> col = np.array([0, 1, 1, 0])
>>> data = np.array([1, 2, 4, 8])
>>> csr_matrix((data, (row, col)), shape=(3, 3)).toarray()
array([[9, 0, 0],[0, 2, 0],[0, 4, 0]])


5、csr_matrix((data, indices, indptr), [shape=(M, N)]) is the standard CSR representation where the column indices for row i are stored in indices[indptr[i]:indptr[i+1]] and their corresponding values are stored in data[indptr[i]:indptr[i+1]]. If the shape parameter is not supplied, the matrix dimensions are inferred from the index arrays.

>>> indptr = np.array([0, 2, 3, 6])
>>> indices = np.array([0, 2, 2, 0, 1, 2])
>>> data = np.array([1, 2, 3, 4, 5, 6])
>>> csr_matrix((data, indices, indptr), shape=(3, 3)).toarray()
array([[1, 0, 2],[0, 0, 3],[4, 5, 6]])

【scipy.sparse中csr.matrix的用法】相关推荐

  1. python中flatten_Python中flatten( ),matrix.A用法说明

    flatten()函数用法 flatten是numpy.ndarray.flatten的一个函数,即返回一个折叠成一维的数组.但是该函数只能适用于numpy对象,即array或者mat,普通的list ...

  2. Scipy.sparse中coo_matrix、csc_matrix、csr_matrix、lil_matrix辨析

    简介 1. coo_matrix: 坐标格式的矩阵(Coodrdinate format matrix) data = [1, 1, 1] row = [0, 1, 1] col = [0, 1, 1 ...

  3. Scipy sparse中关于CSC矩阵的自我理解

    官方文档可见:https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csc_matrix.html#scipy.spars ...

  4. Scipy.sparse中coo_matrix、csc_matrix、csr_matrix、lil_matrix区别与特点

    简介 coo_matrix: 坐标格式的矩阵(Coodrdinate format matrix) 优点: 不同稀疏格式间转换效率高(exp:CSR/CSC) coo_matrix不支持元素的存取和增 ...

  5. Python中flatten( ),matrix.A用法

    flatten()函数用法 flatten是numpy.ndarray.flatten的一个函数,即返回一个折叠成一维的数组.但是该函数只能适用于numpy对象,即array或者mat,普通的list ...

  6. Python中scipy.sparse的一些整理

    scipy.sparse scipy.sparse的稀疏矩阵类型 scipy.sparse中的矩阵函数 构造函数 判别函数 其他有用函数 scipy.sparse中的作用在矩阵的内函数 针对元素的函数 ...

  7. scipy.sparse的一些整理

    scipy.sparse scipy.sparse的稀疏矩阵类型 scipy.sparse中的矩阵函数 构造函数 判别函数 其他有用函数 scipy.sparse中的作用在矩阵的内函数 针对元素的函数 ...

  8. Scipy.sparse模块中coo_matrix、csc_matrix、csr_matrix区别

    Scipy.sparse模块常用的三种具体形式 coo_matrix :COOrdinate format matrix csc_matrix :Compressed Sparse Column ma ...

  9. Scipy.sparse模块中的coo_matrix、csc_matrix、csr_matrix函数

    三种函数的英文全名,首先是从表面意思上入手. coo_matrix :COOrdinate format matrix(坐标格式矩阵) csc_matrix:Compressed Sparse Col ...

最新文章

  1. LeetCode 468. Validate IP Address--笔试题--Python解法
  2. 百度地图示例左侧的代码编辑器Ace Editor
  3. 读《大学之路》有感①
  4. 操作系统基础:进程知识笔记(二)
  5. 【数据结构基础应用】【查找和排序算法】
  6. C++11新特性的总结
  7. python中怎么安装sklearn_如何安装Sklearn for Reinteract?
  8. Spring Security OAuth2.0_总结_Spring Security OAuth2.0认证授权---springcloud工作笔记157
  9. IDEA右键新建时没有Java Class选项
  10. MS17-010漏洞复现(带win7虚拟机安装,零基础)
  11. 黑马2021最新版 SpringCloud基础篇全技术栈导学(RabbitMQ+Docker+Redis+搜索+分布式)
  12. 微信公众号里的文章图片应该如何原图下载
  13. 【记录】win11安装ubuntu子系统教程
  14. 编写lisp程序解一元二次方程_vb解一元二次方程代码
  15. Unity实现扇形Slider进度条加载功能
  16. base64 的加密和解密
  17. Android音视频视频基础(H264)二 SPS分析
  18. 校招(含实习生春招)指南
  19. 菩提本无树,明镜亦非台,本来无一物,何处惹尘埃(学习)
  20. 量子计算机九章感想,量子计算机九章这么火,本文让你明白什么是量子

热门文章

  1. B3402 [Usaco2009 Open]Hide and Seek 捉迷藏 最短路
  2. 李炎恢教程/妙味课堂javaScript/jQuery/js/Ajax全套视频
  3. 美国普渡大学张如琪助理教授招收机器学习方向博士硕士
  4. 【Linux学习】之chown命令
  5. 华为云企业应用上云解决方案,为企业排忧解难
  6. 【SCP文件传输】广域网下将外网文件传到内网服务器
  7. 软工实践第七次作业——需求分析报告
  8. Python看春运,万条拼车数据背后的春节迁徙地图
  9. 计算机管理 服务在哪,电脑打开服务管理界三种方法【图文教程】
  10. whatsapp协议简单分析