网格到图#
- sklearn.feature_extraction.image.grid_to_graph(n_x, n_y, n_z=1, *, mask=None, return_as=<class 'scipy.sparse._coo.coo_matrix'>, dtype=<class 'int'>)[source]#
- 像素到像素连接的图。 - 如果两个体素连接,则存在边。 - 参数:
- n_xint
- x 轴维度。 
- n_yint
- y 轴维度。 
- n_zint, default=1
- z 轴维度。 
- maskndarray of shape (n_x, n_y, n_z), dtype=bool, default=None
- 图像的可选掩码,仅考虑部分像素。 
- return_asnp.ndarray 或稀疏矩阵类,默认=sparse.coo_matrix
- 用于构建返回的邻接矩阵的类。 
- dtypedtype,默认=int
- 返回的稀疏矩阵的数据。默认值为整数。 
 
- 返回:
- graphnp.ndarray 或稀疏矩阵类
- 计算得到的邻接矩阵。 
 
 - 示例 - >>> import numpy as np >>> from sklearn.feature_extraction.image import grid_to_graph >>> shape_img = (4, 4, 1) >>> mask = np.zeros(shape=shape_img, dtype=bool) >>> mask[[1, 2], [1, 2], :] = True >>> graph = grid_to_graph(*shape_img, mask=mask) >>> print(graph) <COOrdinate sparse matrix of dtype 'int64' with 2 stored elements and shape (2, 2)> Coords Values (0, 0) 1 (1, 1) 1 
