image.img_to_graph返回的值是什么意思? chrome.png这个图像
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors
from sklearn.cluster import spectral_clustering
from sklearn.feature_extraction import image
from PIL import Image
pic = Image.open('Chrome.png')
pic = pic.convert('L')
data = np.array(pic).astype(np.float)
affinity = image.img_to_graph(data)
print(affinity)
print(affinity.shape)
print(type(affinity))
print(affinity.toarray())
返回的结果是:
(0, 1) 0.0039215686274509665
(1, 2) 0.0
(2, 3) 0.0039215686274509665
(3, 4) 0.0
(4, 5) 0.0039215686274509665
(5, 6) 0.0039215686274509665
...
(1388, 1388) 0.43529411764705883
(1389, 1389) 0.42745098039215684
(1390, 1390) 0.4235294117647059
(1391, 1391) 0.4196078431372549
(1392, 1392) 0.41568627450980394
(1393, 1393) 0.4117647058823529
(1394, 1394)
<class 'scipy.sparse.coo.coo_matrix'>
[[0.81960784 0.00392157 0. ... 0. 0. 0. ]
[0.00392157 0.81568627 0. ... 0. 0. 0. ]
[0. 0. 0.81568627 ... 0. 0. 0. ]
...
[0. 0. 0. ... 0.41960784 0.00392157 0. ]
[0. 0. 0. ... 0.00392157 0.41568627 0.00392157]
[0. 0. 0. ... 0. 0.00392157 0.41176471]]
为什么稀疏矩阵刚开始的时候行索引和列索引不一样,后面几行行索引和列索引又一样了?为什么稀疏矩阵没有包含(0,0) 0.81960784这一项?是34*41的
忽然笑
相关分类