我们如何生成一行和一列之和为1的矩阵。
import numpy as np
import random
class city:
def __init__(self):
self.distance()
def distance(self):
self.A = np.array([[ 0, 10, 20, 30],[10, 0, 25, 20],[20, 25, 0, 15],[30, 20, 15, 0]])
self.B =(np.random.randint(0, self.A.shape[0], size=self.A.shape[0]) == np.arange(self.A.shape[0]).reshape(-1, 1)).astype(int)
return self.B