## `adjacency_matrix(F)`

Computes the sparse adjacency matrix from a face list or a list of edges.

Parameters:

Name Type Description Default
`F` `(m,k) triangle or edge list.`

If k=2, this is assumed to be an edge list; if k=3, this is assumed to be a triangle list of a triangle mesh.

required

Returns:

Name Type Description
`A` `(n,n) scipy csr sparse matrix.`

``````V,F = gpy.read_mesh("mesh.obj")
Source code in `src/gpytoolbox/adjacency_matrix.py`
 ``` 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44``` ``````def adjacency_matrix(F): """Computes the sparse adjacency matrix from a face list or a list of edges. Parameters ---------- F : (m,k) triangle or edge list. If k=2, this is assumed to be an edge list; if k=3, this is assumed to be a triangle list of a triangle mesh. Returns ------- A : (n,n) scipy csr sparse matrix. sparse adjacenct matrix Examples -------- ```python V,F = gpy.read_mesh("mesh.obj") A = gpy.adjacency_matrix(F) ``` """ if F.size==0: return sp.sparse.csr_matrix() if F.shape[1]==2: E = F elif F.shape[1]==3: E = edges(F) else: assert False, "Unsupported dimension of F." n = np.max(E)+1 A = sp.sparse.csr_matrix( (np.ones(2*E.shape[0]), (np.concatenate((E[:,0], E[:,1])), np.concatenate((E[:,1],E[:,0])))), shape=(n,n), dtype=int) return A ``````