KOTA ITO

Generation

generate functionWed, 07 Dec 2022

pandasデータフレームから隣接行列を作成する。

def _make_adjacency_matrix(df, number, thres=0, normalize=False): num_max = df.shape[0] result = np.zeros((num_max, num_max), dtype=np.float32) for i in range(num_max): for j in range(num_max): result[i][j] = abs(df.iloc[i, number] - df.iloc[j, number]) result[result < thres] = 0 if normalize: result[result > 0] = 1 return result

Questions about programming?Chat with your personal AI assistant