Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.
in = VertexInDegree[F];
out = VertexOutDegree[F];

I want both in and out to be ordered by in. Example: graph has nodes a,b,c with indegrees 1,2,0 and outdegrees 0,1,2. I want lists in = {0,1,2} and out = {2,0,1}.

How do I do this? I tried

in = Sort[VertexInDegree[F]];
out = VertexOutDegree[F][[Ordering@in]];

, but this didn't give the expected result.

share|improve this question
    
You want to use Ordering on the data before sorting. Try out = VertexOutDegree[F][[Ordering@VertexInDegree[F]]]. –  Rahul May 19 at 16:53

1 Answer 1

g = RandomGraph[BernoulliGraphDistribution[10, 0.2], DirectedEdges -> True];
inout = Through[{VertexInDegree, VertexOutDegree}[g]]
(* {{2, 0, 2, 0, 3, 3, 2, 3, 1, 3}, {1, 2, 0, 2, 4, 3, 1, 2, 3, 1}} *)
#\[Transpose][[Ordering[First@#]]]\[Transpose] &@inout
(* {{0, 0, 1, 2, 2, 2, 3, 3, 3, 3}, {2, 2, 3, 1, 0, 1, 4, 3, 2, 1}}*)
share|improve this answer

Your Answer

 
discard

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.