Message Boards Message Boards

4
|
4136 Views
|
1 Reply
|
6 Total Likes
View groups...
Share
Share this post:

Why are WeightedAdjacencyMatrix and WeightedAdjacencyGraph inconsistent?

Posted 7 years ago
POSTED BY: Szabolcs Horvát

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.

POSTED BY: Szabolcs Horvát
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract