Coulis
Coulis

Reputation: 194

Copying only a part of a list of list

I am actually developping a clustering algorithm with Python (because I want to learn it). First of all, here's my data format :

[DATA] = [[G1],[G2], ... ,[GX]] [GX] = [[Nodes][Edges]] [Nodes] = [[N1],[N2], ... ,[NX]] [N1] = [1.2 4.57851 47.1245 ...]

In other words, to access any data stored, I must proceed like this :

data[X][0][Y] = The Y [Y] node [0] of the X [X] graph

I'm now trying to copy only the nodes of every graph in the database. So my first thought were something like

only_nodes = data[:][0][:]

For me, it means " Take every [:] nodes [0] from every [:] graphs "

But it doesn't seems to work very well, as I ended with the 1st graph (as if I asked for data[0]). I'm pretty new with Python, and I'd like to know if you see what's wrong. Any suggestion is welcome !

Upvotes: 0

Views: 70

Answers (1)

myildirim
myildirim

Reputation: 2428

You are missing define to which data you want to select from the data list;

data = [[G1],[G2], ... ,[GX]]
[GX] = [[Nodes][Edges]]
[Nodes] = [[N1],[N2], ... ,[NX]]
[N1] = [1.2 4.57851 47.1245 ...]

data[data.index('GX')][O][:]

Upvotes: 1

Related Questions