202113224

data_cat = sparse.hstack((data_cat, data_))
横向合并
df_tfidf = pd.DataFrame(data_cat.toarray())
csr转成dataframe

20210222


csr_matrix 的数据格式

上面那种数据格式改成下面这种形式
下面的零为行数 第几行
0,1,2,3 是索引
第三列是具体的值

概述
在用python进行科学运算时,常常需要把一个稀疏的np.array压缩,这时候就用到scipy库中的sparse.csr_matrix(csr:Compressed Sparse Row marix) 和sparse.csc_matric(csc:Compressed Sparse Column marix)

scipy.sparse.csr_matrix

官方API介绍(省略前几种容易理解的了)
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]])
# 按row行来压缩
# 对于第i行,非0数据列是indices[indptr[i]:indptr[i+1]] 数据是data[indptr[i]:indptr[i+1]]
# 在本例中
# 第0行,有非0的数据列是indices[indptr[0]:indptr[1]] = indices[0:2] = [0,2]
# 数据是data[indptr[0]:indptr[1]] = data[0:2] = [1,2],所以在第0行第0列是1,第2列是2
# 第1行,有非0的数据列是indices[indptr[1]:indptr[2]] = indices[2:3] = [2]
# 数据是data[indptr[1]:indptr[2] = data[2:3] = [3],所以在第1行第2列是3
# 第2行,有非0的数据列是indices[indptr[2]:indptr[3]] = indices[3:6] = [0,1,2]
# 数据是data[indptr[2]:indptr[3]] = data[3:6] = [4,5,6],所以在第2行第0列是4,第1列是5,第2列是6

scipy.sparse.csc_matrix

官方API介绍(省略前几种容易理解的了)
csc_matrix((data, indices, indptr), [shape=(M, N)])
is the standard CSC representation where the row indices for column 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])
>>> csc_matrix((data, indices, indptr), shape=(3, 3)).toarray()
array([[1, 0, 4],[0, 0, 5],[2, 3, 6]])
# 按col列来压缩
# 对于第i列,非0数据行是indices[indptr[i]:indptr[i+1]] 数据是data[indptr[i]:indptr[i+1]]
# 在本例中
# 第0列,有非0的数据行是indices[indptr[0]:indptr[1]] = indices[0:2] = [0,2]
# 数据是data[indptr[0]:indptr[1]] = data[0:2] = [1,2],所以在第0列第0行是1,第2行是2
# 第1行,有非0的数据行是indices[indptr[1]:indptr[2]] = indices[2:3] = [2]
# 数据是data[indptr[1]:indptr[2] = data[2:3] = [3],所以在第1列第2行是3
# 第2行,有非0的数据行是indices[indptr[2]:indptr[3]] = indices[3:6] = [0,1,2]
# 数据是data[indptr[2]:indptr[3]] = data[3:6] = [4,5,6],所以在第2列第0行是4,第1行是5,第2行是6

scipy csr_matrix csc_matrix相关推荐

  1. 看的懂的scipy.sparse.csr_matrix和scipy.sparse.csc_matrix

    一.导入   在用python进行科学运算时,常常需要把一个稀疏的np.array压缩,这时候就用到scipy库中的sparse.csr_matrix函数和sparse.csc_matric函数.   ...

  2. scipy csr_matrix和csc_matrix函数详解

    概述 在用python进行科学运算时,常常需要把一个稀疏的np.array压缩,这时候就用到scipy库中的sparse.csr_matrix(csr:Compressed Sparse Row ma ...

  3. scipy csr_matrix和csc_matrix函数的用法(通俗易懂版)

    概述 scipy.sparse库中的函数 为了将稀疏的np.array数据进行压缩 两者一个是行一个是列,基本思想差不多 csr_matrix >>> indptr = np.arr ...

  4. python 的csr_Python scipy.sparse.csr_matrix()[csc_matrix()]

    csr_matrix是Compressed Sparse Row matrix的缩写组合,下面介绍其两种初始化方法 csr_matrix((data, (row_ind, col_ind)), [sh ...

  5. 深度学习网络模型可视化netron

    很多时候,复现人家工程的时候,需要了解人家的网络结构.但不同框架之间可视化网络层方法不一样,这样给研究人员造成了很大的困扰. 前段时间,发现了一个可视化模型结构的神奇:Netron 查看全文 http ...

  6. listary 指定目录搜索_everything

    20211009 https://zhuanlan.zhihu.com/p/225414423 listary详细使用 20210710 everything搜索文件,结果出现相同的2个重复情况,路径 ...

  7. 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 ...

  8. csr_matrix和csc_matrix简析

    一.概念 csr_matrix(Compressed Sparse Row matrix)或csc_matric(Compressed Sparse Column marix),为压缩稀疏矩阵的存储方 ...

  9. python scipy 稀疏矩阵详解

    文章目录 稀疏矩阵格式 coo_matrix csr_matrix csc_matrix lil_matrix dok_matrix dia_matrix bsr_matrix 实用函数 经验总结 参 ...

最新文章

  1. numpy 中的 squeeze() 函数
  2. Meta AI发布图音文大一统模型Data2vec,4天在GitHub揽1.5万星
  3. 【408预推免复习】操作系统之处理机调度与死锁
  4. HTTP Error 500.21
  5. 一個全世界最珍貴的故事(轉載)
  6. 当ABAP遇见普罗米修斯
  7. Java面试题及答案2020,kafka教程分享
  8. 用计算机打出二分之一,win10手机计算器怎么输入二分之一?
  9. react-redux笔记
  10. 用习惯了windows系统要怎样去认识linux系统(三)
  11. Firefox和Chrome浏览器导出书签
  12. dropbox 、tombstones、debuggred
  13. 计算机网络:从物理层到应用层的五层模型
  14. 数据结构相关重点(个人总结)
  15. C++:实现量化GSR模型测试实例
  16. Xmind思维导图编写测试点,便于扩展测试用例(详细)
  17. mysql 时间戳查询当天数据_mysql 时间戳查询 当天 本周 当月 数据
  18. 5G/4G边缘计算网关 智能边缘网关TG463
  19. Python List列表函数大全
  20. python利用有道的url来进行翻译英文单词与句子,并且实现了自动生成指定位置的文件夹来存储

热门文章

  1. js异步提交form表单的解决方案
  2. 2022-2028年中国冶金工业节能减排投资分析及前景预测报告
  3. 2022-2028年中国气相防锈薄膜行业市场发展调研及投资前景分析报告
  4. eclipse运行maven web项目
  5. PyCharm 使用技巧
  6. tf.expand_dims()
  7. LeetCode简单题之区域和检索 - 数组不可变
  8. TVM性能评估分析(六)
  9. C ++基本输入/输出
  10. Waymo的自主进化