[python-uk] Help Please

2007-01-28 Thread Python Freak

Hi,

This may be too elementary for most of you, but could you please help me
with the following question? I would like to use comprehensive lists and
lists of lists. Where do I start?

Question:

Consider a digraph with 10 vertices, labeled 1 through 10. You are given the
following adjacency list representation, where we first list the vertices
adjacent to vertex 1, and so on.

1*; *2; 2*; *3; 3*; *4; 4*; *5; 5*; *6; 6*; *7; 7*; *8; 8*; *9; 9*; *10; 10.


a) Write code to turn the adjacency list into an incidence list and an an
adjacency matrix.

b) Write code to turn the incidence list into an adjacency matrix.

Hint: You may find it useful to note that one incidence list representation
is (1*; *1), (2*; *2), (3*; *3), (4*; *4), (5*; *5),(6*; *6), (7*; *7), (8*;
*8), (9*; *9), (10*; *10), (1*; *2), (2*; *3), (3*; *4), (4*; *5), (5*; *6),
(6*; *7), (7*; *8), (8*; *9), (9*; *10).
___
python-uk mailing list
python-uk@python.org
http://mail.python.org/mailman/listinfo/python-uk


Re: [python-uk] Help Please

2007-01-28 Thread Python Freak

Guys,

The question I posted is taken from an exercise sheet which I will discuss
with my study group -- nothing graded. I am a graduate student trying to
learn Python for some application in microeconomics. As I am new to Python,
I am clueless about where to start. I apologise if this caused any
inconvenience -- I didn't know that you are not allowed to answer problems.
Michael's response definitely helps but I would appreciate a little more
help.

Thanks.


On 1/28/07, Zeth Green <[EMAIL PROTECTED]> wrote:


On 29/01/07, Michael Sparks <[EMAIL PROTECTED]> wrote:
> Is this homework?

I was about to respond with a literal answer but I thought that too.
It was the mathematical terminology but especially this bit that made
me suspect:

> On Sunday 28 January 2007 22:45, Python Freak wrote:
Hint: You may find it useful to note that one incidence list
representation is...
___
python-uk mailing list
python-uk@python.org
http://mail.python.org/mailman/listinfo/python-uk

___
python-uk mailing list
python-uk@python.org
http://mail.python.org/mailman/listinfo/python-uk


Re: [python-uk] Help Please

2007-01-28 Thread Python Freak

Okay, how about this:

I don't know how to create the adjacency list at the first place! Can you
get me started please? If I start then I can make an attempt to create the
incidence list and the adjacency matrix representation. Here is the question
again:

Consider a digraph with 10 vertices, labeled 1 through 10. You are given the
following adjacency list representation, where we first list the vertices
adjacent to vertex 1, and so on.

1*, *2; 2*, *3; 3*, *4; 4*, *5; 5*, *6; 6*, *7; 7*, *8; 8*, *9; 9*, *10; 10.


a) Write code to turn the adjacency list into an incidence list and an an
adjacency matrix.

b) Write code to turn the incidence list into an adjacency matrix.




On 1/28/07, Zeth Green <[EMAIL PROTECTED]> wrote:


On 29/01/07, Python Freak <[EMAIL PROTECTED]> wrote:
> I am clueless about where to start.

Okay, I did economics for my first degree so we have something in
common! (Although I am not sure my maths ever got that deep). There
are many ways to do what you want. The first step is to mentally
translate what you want to do into Python's data types.

See here for a list of the basic types:
http://docs.python.org/tut/node7.html

Do not forget you can nest data types inside each other, so the most
basic matrix is a set of lists inside a list.

However once you understand what you are trying to do, it would then
be worth downing tools and looking into the numpy module as it has
many mathematical constructs all ready and abstracted for you.

Look at http://numpy.scipy.org/ for hours of fun(?). See for example,

https://networkx.lanl.gov/Reference/networkx.convert-module.html#to_numpy_matrix
___
python-uk mailing list
python-uk@python.org
http://mail.python.org/mailman/listinfo/python-uk

___
python-uk mailing list
python-uk@python.org
http://mail.python.org/mailman/listinfo/python-uk


Re: [python-uk] Help Please

2007-01-29 Thread Python Freak

Okay I finally got the adjancency list representation working:

  v = range(1,11)
  al=zip(v[:-1],v[1:])+[(10,)]

Is that right? It works fine.

How do I go from here to creating an incidence list representation and
adjacency matrix? (is it possible to assign to individual items in each
tuple? I guess not).

[ for those of you who missed my earlier email, this is not a homework; i'm
a graduate student attempting to learn python ].


On 1/28/07, Zeth Green <[EMAIL PROTECTED]> wrote:


On 29/01/07, Michael Sparks <[EMAIL PROTECTED]> wrote:
> Is this homework?

I was about to respond with a literal answer but I thought that too.
It was the mathematical terminology but especially this bit that made
me suspect:

> On Sunday 28 January 2007 22:45, Python Freak wrote:
Hint: You may find it useful to note that one incidence list
representation is...
___
python-uk mailing list
python-uk@python.org
http://mail.python.org/mailman/listinfo/python-uk

___
python-uk mailing list
python-uk@python.org
http://mail.python.org/mailman/listinfo/python-uk