Skip to contents

Create an undirected graph from an adjacency matrix

Usage

nug_from_adj_mat(adj_mat, ...)

Arguments

adj_mat

A square symmetric matrix. Nonzero entries indicate edges; their values are used as edge weights. Self-loops are not allowed.

...

Additional arguments: seed (integer) for reproducible RNG.

Value

A NaturalUndirectedGraph object.

See also

Examples

# 4-vertex path graph from adjacency matrix
A <- matrix(0, 4, 4)
A[1, 2] <- A[2, 1] <- 1
A[2, 3] <- A[3, 2] <- 1
A[3, 4] <- A[4, 3] <- 1
g <- nug_from_adj_mat(A)
g$nedges()
#> [1] 3