Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to find the total weight of an WeightedAdjacencyGraph. I have a graph in that form

a = WeightedAdjacencyGraph[{...},{...},{...}....etc]

How can I find its total weight?

share|improve this question

You could just do this: if a graph is undirected:

Total[UpperTriangularize[WeightedAdjacencyMatrix[g]], 2]

if a graph is directed:

Total[WeightedAdjacencyMatrix[g], 2]

or by PropertyValue

Total[PropertyValue[g, EdgeWeight]]
share|improve this answer
Don't forget the self loops! – Szabolcs Oct 12 '13 at 19:23
@Szabolcs thanks, I missed that. – halmir Oct 13 '13 at 4:39

This should deal with undirected, directed and graphs with loops (non-infinite non-zero diagonal elements):

totalweight=Total@(PropertyValue[{g, #}, EdgeWeight] & /@ EdgeList[g])

where g is graph of interest

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.