networkx - Iterating through and changing nested list entries in Python -


Everyone is writing a simple function in Python 2.7, which is to test using the Networks 1.9 module My graph algorithm implementation works correctly. For this, I have a list, Divix, in which there is a list for each block in the division of lists, which gives information about the edges of each node in the classes in the partition. Take a swan:

Block in the list block: block no = p.index (block) dvecs [blockNo] = [[-1] * numBlocks] * lane for node in block: node = block for other.index (node) p P: Other block nozz = P.index (otherBlock) dvecs [blockNo] [nodeNo] [otherBlockNo] = len (set (nx.neighbors (G, node)) intersection (set (other block))

The problem that comes to me That is, in the last row of the nested loop, the line begins with DVC [block non ...], according to the debugger, each entry from the center depth list (one node specified by the node specified in the index) interval For each recurrence of the loop, it is being updated with the same value. In other words, it seems that the 'node' is being kept continuously and all the nodes in the block are node nodes Moving. What is happening?

In response to the Romans, I tried the following: Block

 , in the number (P) for the block: dvecs [blockNo] = [[-1] * Numblocks] * Node for node, node in enumerate (block): For other blocks, enumerate in other blocks (p): dvecs [blockNo] [nodeNo] [otherBlockNo] = len (set (nx. Neighbors live, node)). Intersection (set (other block)))   

However, I am receiving the same behavior. Did I forget something?

this:

  [[]] * n   

provides you with a list of same empty list, n bar, then adding "none" to all of them by adding one of them There is a nested list.

Try it out, which will create separate blank lists:

  [[_ for category]]    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -