我有以下代码,其中定义了类和def。 在这里,我们正在读取一个文件,其中包含开始节点,结束节点以及两个节点之间的距离。
示例: 1 3 100 2 4 200 ..so on ..
import numpy as np
import pandas as pd
# STEP 1: Get the inout options to choose between shortest path and all configuration
path_type = int(input("Choose the option1 or option2 "))
if path_type == 1:
st_nd = int(input("Enter the start node: "))
ed_nd = int(input("Enter the end node: "))
# STEP 2: Import the data file
def import_data():
global data_points_df # Data_points
global data_points_max # NN
global Dist # Dist
global data_points_arr # NData_points
# Read the data as data frame
data_points_df = pd.read_csv('./Exercises/dp.txt', delimiter="\t")
data_points_arr = np.array(data_points_df)
data_points_max = np.max(data_points_arr[:, 0:2])
print(data_points_df)
print(data_points_arr)
print(data_points_max)
def Find_Adjacent_Nodes():
global K
global data_points_max # NN
K = np.array([]) # Empty Array
for i in range(data_points_max + 1):
result = np.where(data_points_arr[:, 0:2] == i)
print(i, result)
temp = data_points_arr[result[0], (result[1] + 1) % 2]
print(temp)
dst = data_points_arr[result[0], (result[1]) % 1 + 2]
print(dst)
print(Find_Adj_node(temp, dst))
K = np.append(K, Find_Adj_node(temp, dst))
return K
class Find_Adj_node:
Adj_nod = []
Nod_dist = []
def __init__(self, M, N):
self.Adj_nod = M
self.Nod_dist = N
if path_type == 1:
import_data()
Find_Adjacent_Nodes()
'''
when I run the command I see the following message.
9 (array([5, 7], dtype=int32), array([1, 1], dtype=int32))
[7 6]
[ 200 2000]
<__main__.Find_Adj_node object at 0x0DE643E8>
我想检查K中的内容以及它的分配方式。从逻辑上讲,我知道它具有[7,6]和相应的距离值[200 2000]。问题是如何打印并查看。
尝试了k。*一些选项,但找不到。
BR, SemiCode