python - 为什么 Networkx 和关联矩阵计算的拉普拉斯算子不同

标签 python linear-algebra networkx

import networkx as bx
import numpy as np
G1 = nx.erdos_renyi_graph(20, .3)
L1 = nx.linalg.laplacian_matrix(G1)
A1=nx.incidence_matrix(G1)
L1_inc = A1*np.transpose(A1)
L1_inc == L1

但答案并不适用于所有元素。既然拉普拉斯算子没有方向,那么有什么问题吗?

如果您需要更多信息,请告诉我。

最佳答案

函数nx.incidence_matrix()默认给出一个无向的关联矩阵。您可以通过 orient=True 返回定向版本。 例如:

In [1]: import networkx as nx

In [2]: G = nx.path_graph(4)

In [3]: I = nx.incidence_matrix(G,oriented=True)

In [4]: I.todense()
Out[4]: 
matrix([[-1.,  0.,  0.],
        [ 1., -1.,  0.],
        [ 0.,  1., -1.],
        [ 0.,  0.,  1.]])

In [5]: L = nx.laplacian_matrix(G)

In [6]: L.todense()
Out[6]: 
matrix([[ 1, -1,  0,  0],
        [-1,  2, -1,  0],
        [ 0, -1,  2, -1],
        [ 0,  0, -1,  1]])

In [7]: (I*I.T).todense()
Out[7]: 
matrix([[ 1., -1.,  0.,  0.],
        [-1.,  2., -1.,  0.],
        [ 0., -1.,  2., -1.],
        [ 0.,  0., -1.,  1.]])

关于python - 为什么 Networkx 和关联矩阵计算的拉普拉斯算子不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26644431/

相关文章:

python - BeautifulSoup 和 lxml 找不到 div 元素

python - 如何使用 python 变量运行多个 Linux 命令

linear-algebra - MATLAB : How do I ensure that the covariance matrix is positive definite when using Kalman Filter

ios - 也围绕自身中心旋转物体吗?

python - 来自嵌套单词列表的共现矩阵

python - 如何在粗线上获得非圆形箭头?

python - 使用嵌套 defaultdict 重新分配 pandas 系列值

Python bool 运算符的优先级规则

c++ - 如何使用gsl在C++上实现左矩阵除法

python - 如何使用python绘制可读的,最好是交互式的网络图?