我不确定我是否正确理解了这个问题,但我认为你可能想要的是:
import numpy as np
m = np.array([[1. , 0.5, 0. ], [0.5, 1. , 0.5], [0. , 0.5, 1. ]])
a = np.tensordot(m, m, axes=0)
a = a.transpose((0, 2, 1, 3)).reshape((9, 9))
print(a)
输出:
[[1. 0.5 0. 0.5 0.25 0. 0. 0. 0. ]
[0.5 1. 0.5 0.25 0.5 0.25 0. 0. 0. ]
[0. 0.5 1. 0. 0.25 0.5 0. 0. 0. ]
[0.5 0.25 0. 1. 0.5 0. 0.5 0.25 0. ]
[0.25 0.5 0.25 0.5 1. 0.5 0.25 0.5 0.25]
[0. 0.25 0.5 0. 0.5 1. 0. 0.25 0.5 ]
[0. 0. 0. 0.5 0.25 0. 1. 0.5 0. ]
[0. 0. 0. 0.25 0.5 0.25 0.5 1. 0.5 ]
[0. 0. 0. 0. 0.25 0.5 0. 0.5 1. ]]