Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

networkx - unique combinations of paths

# Unique combinations of paths
gg = nx.complete_graph(6)         # Create a complete graph
nx.draw(gg, with_labels = True)   # Plot graph
source = 0                        # Set source node
target = 3                        # Set target node
gg.remove_edge(0, 3)

paths = nx.all_simple_paths(gg, source=source, target=target, cutoff=5)    # Find all paths between two nodes

# Method 1
s = set(map(frozenset, paths))                                             # Remove duplicates {frozenset({0, 3, 4}), frozenset({0, 2, 3})...  
non_redundant_paths = [[source, *[*p-{source,target}],target] for p in s]

# Method 2
non_redundant_paths = []
seen = []
for p in paths:
    if set(p) not in seen:                 # Keep track of the seen ones using a set
        non_redundant_paths.append(p)
        seen.append({*p})
        
print(non_redundant_paths)
Comment

PREVIOUS NEXT
Code Example
Python :: importare un foglio di un file excel in python 
Python :: frequency domain parameter of speech 
Python :: blue ray size 
Python :: nums: List[int] in python function 
Python :: Convert torch.nn.Embedding layer to numpy array 
Python :: looping over folder to extract zip winrar python 
Python :: repeat printing rows excel using python whenever i run the script 
Python :: transfer sound to hz with python 
Python :: sqlalchemy filter getattr 
Python :: pygame kreis definition 
Python :: torch split classes stratified 
Python :: not staments python 
Python :: python find multiple matches in string 
Python :: pip unknown command import 
Python :: how to display text on boxplot in python 
Python :: inspect rows in dictionary pthon 
Python :: sqlalchemy create engine SQLite Absolute 
Python :: create a list with user defined name of list 
Python :: Python Creating a Tuple 
Python :: Python Raw string using r prefix 
Python :: Python - pasword hashed 
Python :: input what is your name python 
Python :: to remove whitspace in string 
Python :: ing or ly add to str 
Python :: Create an x amount of unique random fixed size strings 
Python :: NMF cosine similarities 
Python :: how to calculate the area and perimeter of a shape in python 
Python :: how to choose appropriate graph for dataset visualization 
Python :: looping through models and plotting their performance 
Python :: Create list element using algebraic operation 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =