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)=
A.shape[0]= 4
A.shape[1]= 3

你可能感兴趣的:(机器学习python,python,深度学习,机器学习)