Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么Networkx和关联矩阵计算的拉普拉斯算子不同_Python_Linear Algebra_Networkx - Fatal编程技术网

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

Python 为什么Networkx和关联矩阵计算的拉普拉斯算子不同,python,linear-algebra,networkx,Python,Linear Algebra,Networkx,但答案并非适用于所有要素。既然拉普拉斯不定向,怎么了 如果您需要更多信息,请告诉我。函数nx.incidence\u matrix()默认提供无方向关联矩阵。您可以传递oriented=True以返回定向版本。 例如: 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

但答案并非适用于所有要素。既然拉普拉斯不定向,怎么了


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

函数nx.incidence\u matrix()默认提供无方向关联矩阵。您可以传递oriented=True以返回定向版本。 例如:

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

谢谢你,阿里。如果我错了,请纠正我,为了计算拉普拉斯,我们应该使用定向(定向)关联矩阵,即使G是无向的。
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.]])