首页 > 其他 > 详细

csr_matrix矩阵用法小节

时间:2020-05-24 20:42:55      阅读:107      评论:0      收藏:0      [点我收藏+]
from scipy.sparse import *
 
row =  [0,0,0,1,1,1,2,2,2]#行指标
col =  [0,1,2,0,1,2,0,1,2]#列指标
data = [1,0,1,0,1,1,1,1,0]#在行指标列指标下的数字
team = csr_matrix((data,(row,col)),shape=(3,3))
print(team)
print(team.todense())  # 返回稀疏矩阵的np.matrix形式
 
 
输出结果:
  (0, 0)    1
  (0, 1)    0
  (0, 2)    1
  (1, 0)    0
  (1, 1)    1
  (1, 2)    1
  (2, 0)    1
  (2, 1)    1
  (2, 2)    0
[[1 0 1]
 [0 1 1]
 [1 1 0]]
 
Process finished with exit code 0

 

row =  [0,0,0,0,1,1,1,1,2,2,2,2]#行指标
col =  [0,1,2,3,0,1,2,3,0,1,2,3]#列指标
data = [1,0,1,1,0,1,1,1,1,0,1,1]#在行指标列指标下的数字
team = csr_matrix((data,(row,col)),shape=(3,4))
# print(team)
# print(team.todense())
team_dok = team.todok()  # 返回稀疏矩阵的dok_matrix形式
# print(team_dok)
 
team_coo = team_dok.tocoo()  # 返回稀疏矩阵的coo_matrix形式

 

csr_matrix矩阵用法小节

原文:https://www.cnblogs.com/SupremeBoy/p/12952266.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!