我试图获得两个巨大的文本文件,将他们的数据合并成一个文本文件。
一个文本文件包含200000到500000行[node_id, x, y, z, temperature],另一个包含向量的203000行文件。
其思想是识别从一个文件到另一个文件中的向量的节点,并将它们组合成一个新的文本文件。我设法将这两个文件放入3-6k行的块中来管理时间,但我只能想到:
for循环,以获得起始坐标和结束坐标。for循环每个节点以检查向量框的坐标。这仍然在一个for循环中创建5000次迭代的嵌套循环,在其中嵌套了另5000次循环迭代。有更快的方法吗?
节点文件示例: node_id,x,y,z,temp
21,-10.0,-12.0,4.0,160,0
向量文件的示例: vector_time,x,y,z,wattage
8.83,-9.82,-3.16,0.05。150.00
我试过:
with open(rf'Node_Temp_result.txt', 'r') as nodeFile:
nodesInfo = nodeFile.readlines()
with open(rf'laser.txt', 'r') as laserFile:
laserInfo = laserFile.readlines()
for laser in tqdm(range(currentLaserMin, currentLaserNext)):
local_laser = Split(laserInfo, laser)
laser_search = Laser(local_laser.col0(), local_laser.col1(), local_laser.col2(), local_laser.col3(), local_laser.col4())
splits = 0
x_search_laser = laser_search.laser_x()
y_search_laser = laser_search.laser_y()
z_search_laser = laser_search.laser_layer()
if layer - 1 < z_search_laser <= layer and laser_search.laser_power() > 0:
laser_next = Split(laserInfo, laser + 1)
laser_search_next = Laser(laser_next.col0(), laser_next.col1(), laser_next.col2(), laser_next.col3(), laser_next.col4())
x_start = x_search_laser
x_end = laser_search_next.laser_x()
y_start = y_search_laser
y_end = laser_search_next.laser_y()
num = 0
for node in range(currentNodeMin, currentNodeNext):
local_node = Split(nodesInfo, node)
node_search = Node(local_node.col0(), local_node.col1(), local_node.col2(), local_node.col3(), local_node.col4())
x_search_node = node_search.node_x()
y_search_node = node_search.node_y()
z_search_node = node_search.node_layer()
if node_search.node_temp() > 250:
if layer - 1 < z_search_node <= layer:
if x_start <= x_search_node <= x_end and y_start <= y_search_node <= y_end:
crossLocations = cross_finder(x_start, x_end, y_start, y_end)
if crossLocations[3] < 0.07:
splits += 1
'append the node to the vector'
发布于 2022-06-13 08:13:38
您可以考虑执行此任务的一些选项是:
使用Python的https://docs.python.org/3/library/multiprocessing.html
。
https://stackoverflow.com/questions/72599424
复制相似问题