python 3.x - How to get the laplacian matrix for a directed weighted network using networkX? -


i facing problem when changing weights not reflected in laplacian matrix

import numpy np import networkx nx #construction of directed graph g=nx.digraph() #adding weights links g.add_weighted_edges_from([(1,2,0.65), (3,1,0.35),(2,3,0.85)]) #extracting  l = nx.directed_laplacian_matrix(g)  l = nx.directed_laplacian_matrix(g) print(l) 

this behaviour arises because digraph triangle:

enter image description here

if additional edge added:

enter image description here

the laplacian reflects weights:

import networkx nx g = nx.digraph() g.add_weighted_edges_from([(1,2,0.65), (3,1,0.35), (2,3,0.85), (3,4,0.2)]) nx.directed_laplacian_matrix(g) out[1]: matrix([[ 0.9875    , -0.45383656, -0.35847072, -0.10930101],         [-0.45383656,  0.9875    , -0.45936416, -0.10267954],         [-0.35847072, -0.45936416,  0.9875    , -0.34072508],         [-0.10930101, -0.10267954, -0.34072508,  0.75      ]]) 

if edge weight updated, laplacian reflects this:

g[3][1]['weight'] = 0.8 nx.directed_laplacian_matrix(g) out[2]: matrix([[ 0.9875    , -0.47030901, -0.41990635, -0.0840537 ],         [-0.47030901,  0.9875    , -0.47223262, -0.08179532],         [-0.41990635, -0.47223262,  0.9875    , -0.25329959],         [-0.0840537 , -0.08179532, -0.25329959,  0.75      ]]) 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -