grid_to_graph
- sklearn.feature_extraction.image.grid_to_graph(n_x, n_y, n_z=1, *, mask=None, return_as=<class 'scipy.sparse._coo.coo_array'>, dtype=<class 'int'>)[исходный код]
-
Граф связей между пикселями.
Рёбра существуют, если 2 вокселя соединены.
Подробнее см. в руководстве пользователя.
- Параметры:
-
- 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 or a sparse matrix class, default=sparse.coo_array
-
Класс, используемый для создания возвращаемой матрицы смежности.
- dtypedtype, default=int
-
Тип данных возвращаемой разреженной матрицы. По умолчанию — int.
- Возвращает:
-
- graphnp.ndarray or a sparse matrix class
-
Вычисленная матрица смежности.
Примеры
>>> 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
© 2007–2026 The scikit-learn developers
Licensed under the 3-clause BSD License.
https://scikit-learn.org/1.9/modules/generated/sklearn.feature_extraction.image.grid_to_graph.html