|
From: | Bernie Hogan |
Subject: | Re: [igraph] Non square adjacency matrix to edge list |
Date: | Mon, 26 Mar 2012 17:48:27 +0100 |
Hi, What type of non-square matrix? There are two types AFAIK: 1. two mode network, i.e. rows and cols are different nodes 2. missing data, i.e. rows or cols are missing. In either case, I don't know of a way to do this in igraph specifically. Are you working in python or R? In python, you would simply read in the rows and create an edge list in two for loops. It also depends on whether the first row / col is named. If it is, then here is a very dirty way to do that. The code below should work for both. matrix = YOURDATA #consider reading in using csvreader edgetups = [] collabels = rows[0] # there will be a blank first entry, but that's no matter rowlabels = [rows[0] for rows in YOURDATA] #again, first entry blank but no matter #removing first entry here creates off-by-one errors below, so keep for now. for c,i in enumerate(rows): for d,j in enumerate(i): if c > 0 and d > 0 and j > 0: #don't want first row, col, or j if j is 0 edgetups.append(collabels[c],collabels[d]) #Edgetups is now your edgelist. Insert as normal. Take care, BERNiE Dr Bernie Hogan Research Fellow, Oxford Internet Institute University of Oxford On 24 Mar 2012, at 17:39, Tamás Nepusz wrote:
|
[Prev in Thread] | Current Thread | [Next in Thread] |