读代码时遇到这个函数,不知道这个函数到底起了什么样的作用。于是自己测试一下,直观观察该函数的作用
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(type(team)) #<class 'scipy.sparse.csr.csr_matrix'>
print(team.shape) #(3, 3)
print(team)
'''
(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
'''
team.eliminate_zeros()
print(team)
'''
(0, 0) 1
(0, 2) 1
(1, 1) 1
(1, 2) 1
(2, 0) 1
(2, 1) 1
'''