IGraph/M includes IGWeightedAdjacencyGraph
for convenience. It takes an additional argument specifying the matrix element that represents no connection. The default is 0
for consistency with WeightedAdjacencyMatrix
.
Example:
In[4]:= g = Graph[{1 <-> 2, 2 <-> 3}, EdgeWeight -> {4, 5}];
In[5]:= WeightedAdjacencyMatrix[g] // Normal
Out[5]= {{0, 4, 0}, {4, 0, 5}, {0, 5, 0}}
In[6]:= EdgeList@IGWeightedAdjacencyGraph[%]
Out[6]= {1 <-> 2, 2 <-> 3}
As a bonus, IGWeightedAdjacencyGraph
is typically slightly faster than WeightedAdjacencyGraph
.