6-csr_matrix的shape

from scipy.sparse import csr_matrix
#1-创建网络
row = np.array([0, 0, 1, 2, 2, 2, 3])
col = np.array([0, 2, 2, 0, 1, 2, 2])
data = np.array([1, 1, 1, 1, 1, 1,1 ])
A=csr_matrix((data, (row, col)), shape=(4, 3))
print("A=")
print(A)
arr_1=A.toarray()
print("arr_1=")
print(arr_1)
print("A.shape=",A.shape)
print("type(A.shape)=",type(A.shape))
print("A.shape[0]=",A.shape[0])
print("A.shape[1]=",A.shape[1])

A=
(0, 0) 1
(0, 2) 1
(1, 2) 1
(2, 0) 1
(2, 1) 1
(2, 2) 1
(3, 2) 1
arr_1=
[[1 0 1]
[0 0 1]
[1 1 1]
[0 0 1]]
A.shape= (4, 3)
type(A.shape)= <class ‘tuple’>
A.shape[0]= 4
A.shape[1]= 3

猜你喜欢

转载自blog.csdn.net/m0_45496363/article/details/121330892
今日推荐