On 7/20/06, Michael Sorich <[EMAIL PROTECTED]> wrote:
> Can you give an specific example of how this would work? The codes
> really is ugly and it is not clear to me what exactly it does.

ok here's a quick example:

import numpy
n=5
i=3
j=4
A=numpy.random.randint(0,2,(n,n)) #make random graph
A=A-diag(diag(A)) #remove diagonal
A=triu(A)+transpose(triu(A)) #make symmetric

Now say A is the adjacency matrix for a graph and I want to know which
nodes are neighbours of A, but I want to exclude node i from
consideration. So if A is:

array([[0, 1, 0, 1, 0],
       [1, 0, 1, 0, 1],
       [1, 0, 0, 0, 0],
       [0, 0, 1, 0, 1],
       [1, 1, 0, 1, 0]])

the neighbours are array([1]) for i=3, j=4.

One way to do it is to do:

ans=where(A[:,j]==1)[0]
if A[i,j] == 1:
    ans -= 1

which is probably faster than my method. I don't really care so much
about speed though. I'm just trying to figure out different ways of
doing this using numpy.

Dave

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion

Reply via email to