python - Mapping arrays with same values but different orders -
python - Mapping arrays with same values but different orders -
i have 2 arrays of coordinates 2 separate files cfd calculation. 1 mesh file contains connectivity info , other results file.
my problem coordinates each file not in same order. able order arrays results file in same order mesh file.
my thought find matching values of xyz coordinates , create mapping such rest of result arrays can ordered.
i thinking like:
mapping = np.empty(len(co_mesh)) i,coord in enumerate(co_mesh): j in range(len(co_res)): if (coord[0]==co_res[j,0]) , (coord[1]==co_res[j,1]) , (coord[2]==co_res[j,2]): mapping[i] = j
where co_mesh, co_res arrays containing x,y,z coords.
the problem suspect loop take long time. @ moment i'm looping on around 70000 points in future increment 1 1000000 or more.
is there faster way write in python.
i'm using python 2.6.5.
ben
for interested using:
mesh_coords = zip(xm_list,ym_list,zm_list,range(len(x_po))) res_coords = zip(xr_list,yr_list,zr_list,range(len(x))) mesh_coords = sorted(mesh_coords , key = lambda x:(x[0],x[1],x[2])) res_coords = sorted(res_coords , key = lambda x:(x[0],x[1],x[2])) mapping = zip(np.array(listym)[:,-1],np.array(listyr)[:,-1]) mapping = sorted(mapping , key = lambda x:(x[0]))
how sorting coordinate vectors in both files along x y , to the lowest degree z coordinate?
you can efficient , fast if utilize numpy arrays vectors.
update:
if don't have node ids of nodes in result mesh. coordinates same. following:
add numbering additional info vectors. sort both mesh x,y,z add together unsorted numbering of mesh comesh , sort comesh along axis. comesh contains exact order original mesh.
python arrays
Comments
Post a Comment