0

I want to transform a list of the form [['name', label], ..., ['nameN', labelN]] of size n into an nxn matrix with zeros except for places where for certain positions the labels are the same. Basically i want to ultimately make a .csv file that I can put into Gephi and make a network. I tried a "double for loop with an if statement" but contrary to my expectation I obtained all ones.

Here's my code:

list
[['ASV33', 0],
['ASV58', 1],
['ASV61', 0],
['ASV62', 2],
['ASV73', 3],
['ASV75', 4],
['ASV86', 5],
['ASV91', 6],
['ASV99', 7],
['ASV100', 8],
['ASV109', 7],
['ASV110', 9]]

...and so on... Here I make a nxn array of zeros

    rows, cols = (n, n)
    arr = [[0]*cols]*rows

and here s the code where I want to make the cells one if the labels for the columns and the labels for the rows are the same.

for g in range(0,len(list)):
    for h in range(g,len(list)):
        if (list[g][1] == list[h][1]):
            arr[g][h] = 1
            print(g,h)
        else:
            arr[g][h] = 0

Every time I call arr[k][l] I get a one even if list[k][1] != list[l][1]

user4157124
  • 2,809
  • 13
  • 27
  • 42

0 Answers0