如何使用 Python 将邻接矩阵转换为转移矩阵?

How can I use Python to convert an adjacency matrix to a transition matrix?

我正在尝试将矩阵转换为

1 1 0
0 1 1
0 1 1

成为

1 ⅓ 0 
0 ⅓ ½ 
0 ⅓ ½ 

我正在考虑对行求和然后除以它们,但我想知道是否有更好的方法使用 numpy 或 Python 中的任何其他方式来完成此操作。

您可以像下面那样使用 numpy

import numpy as np
arr = np.array([[1, 1, 0],
                [0, 1, 1],
                [0, 1, 1]])

print(arr/arr.sum(axis=0))
[[1.0.33333333 0.]
 [0.0.33333333 0.5]
 [0.0.33333333 0.5]]