8-scipy.sparse与np.mat转换


```python
import numpy as np
from scipy.sparse import csr_matrix
B=np.mat([[0,1,0,0,0],[0,0,0,1,1],[1,1,1,0,0],[0,0,0,0,0],[1,0,0,0,0]])
print("B=")
print(B)
sparseB=csr_matrix(B)
print("sparseB=")
print(sparseB)

`B=
[[0 1 0 0 0]
[0 0 0 1 1]
[1 1 1 0 0]
[0 0 0 0 0]
[1 0 0 0 0]]
sparseB=
(0, 1) 1
(1, 3) 1
(1, 4) 1
(2, 0) 1
(2, 1) 1
(2, 2) 1
(4, 0) 1``

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