【scipy.sparse中csr.matrix的用法】
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的用法】相关推荐
- python中flatten_Python中flatten( ),matrix.A用法说明
flatten()函数用法 flatten是numpy.ndarray.flatten的一个函数,即返回一个折叠成一维的数组.但是该函数只能适用于numpy对象,即array或者mat,普通的list ...
- 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 ...
- Scipy sparse中关于CSC矩阵的自我理解
官方文档可见:https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csc_matrix.html#scipy.spars ...
- Scipy.sparse中coo_matrix、csc_matrix、csr_matrix、lil_matrix区别与特点
简介 coo_matrix: 坐标格式的矩阵(Coodrdinate format matrix) 优点: 不同稀疏格式间转换效率高(exp:CSR/CSC) coo_matrix不支持元素的存取和增 ...
- Python中flatten( ),matrix.A用法
flatten()函数用法 flatten是numpy.ndarray.flatten的一个函数,即返回一个折叠成一维的数组.但是该函数只能适用于numpy对象,即array或者mat,普通的list ...
- Python中scipy.sparse的一些整理
scipy.sparse scipy.sparse的稀疏矩阵类型 scipy.sparse中的矩阵函数 构造函数 判别函数 其他有用函数 scipy.sparse中的作用在矩阵的内函数 针对元素的函数 ...
- scipy.sparse的一些整理
scipy.sparse scipy.sparse的稀疏矩阵类型 scipy.sparse中的矩阵函数 构造函数 判别函数 其他有用函数 scipy.sparse中的作用在矩阵的内函数 针对元素的函数 ...
- Scipy.sparse模块中coo_matrix、csc_matrix、csr_matrix区别
Scipy.sparse模块常用的三种具体形式 coo_matrix :COOrdinate format matrix csc_matrix :Compressed Sparse Column ma ...
- Scipy.sparse模块中的coo_matrix、csc_matrix、csr_matrix函数
三种函数的英文全名,首先是从表面意思上入手. coo_matrix :COOrdinate format matrix(坐标格式矩阵) csc_matrix:Compressed Sparse Col ...
最新文章
- LeetCode 468. Validate IP Address--笔试题--Python解法
- 百度地图示例左侧的代码编辑器Ace Editor
- 读《大学之路》有感①
- 操作系统基础:进程知识笔记(二)
- 【数据结构基础应用】【查找和排序算法】
- C++11新特性的总结
- python中怎么安装sklearn_如何安装Sklearn for Reinteract?
- Spring Security OAuth2.0_总结_Spring Security OAuth2.0认证授权---springcloud工作笔记157
- IDEA右键新建时没有Java Class选项
- MS17-010漏洞复现(带win7虚拟机安装,零基础)
- 黑马2021最新版 SpringCloud基础篇全技术栈导学(RabbitMQ+Docker+Redis+搜索+分布式)
- 微信公众号里的文章图片应该如何原图下载
- 【记录】win11安装ubuntu子系统教程
- 编写lisp程序解一元二次方程_vb解一元二次方程代码
- Unity实现扇形Slider进度条加载功能
- base64 的加密和解密
- Android音视频视频基础(H264)二 SPS分析
- 校招(含实习生春招)指南
- 菩提本无树,明镜亦非台,本来无一物,何处惹尘埃(学习)
- 量子计算机九章感想,量子计算机九章这么火,本文让你明白什么是量子