MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: tab-delimited file to graph

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69455] Re: tab-delimited file to graph
  • From: dh <dh at metrohm.ch>
  • Date: Wed, 13 Sep 2006 04:01:35 -0400 (EDT)
  • References: <ee64q5$7s4$1@smc.vnet.net>

Hi Aitor,
I understand that you have a list: dat of 2 element lists. You are 
looking for a matrix adj that, given 2 elements i,j, has a 1 at 
adj[[i,j]] and a -1 at  adj[[j,i]].
Well, first, create a zero matrix of the requested size:
adj=Array[0 &, {n, n}]
then fill in the 1's:
(adj [[Sequence @@ #]] = 1)& /@ dat
now make the matrix antisymmetric:
adj -= -Transpose[adj]

Daniel

aitor69gonzalez at gmail.com wrote:
> Hello,
> 
> I have a directed graph "mygraph" in a tab delimited file that looks
> like this:
> v1    v2
> v2    v3
> v3    v1
> v1    v4
> I would like to import this graph into mathematica, so that I can take
> advantage of the -DiscreteMath`Combinatorica`- functions. So far, I was
> only able to import it with Import["mygraph","TSV"] into a list of
> two-item lists. Now, I am stuck there. Can somebody help me to convert
> this list of two-item lists into a matrix or adjacency list of a
> directed graph?
> 
> Thank you in advance,
> 
> Aitor
> 


  • Prev by Date: question on changing 'type' of numbers
  • Next by Date: Re: Evaluating a Meijer G-function
  • Previous by thread: Re: tab-delimited file to graph
  • Next by thread: Re: tab-delimited file to graph