Efficient way to merge lists--Programming help
- To: mathgroup at smc.vnet.net
- Subject: [mg12708] Efficient way to merge lists--Programming help
- From: Joel Cannon <cannon at alpha.centenary.edu>
- Date: Wed, 3 Jun 1998 02:20:59 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Cam someone suggest better ways to accomplish the following? I have two lists containing triplets--test is a rectangular array of triplets {x,y,z} (e.g. Dimensions {4,40,3}) and test2 is an array of triplets (e.g. Dimensions {50,3}). test2 is to replace equivalent elements in test (when the x and y values are equal--the test2 z values have been calculated more accurately). The task can be understood to be: 1. Given a triplet {x_i,y_i,z_i} from test2, find the position in test which has the same {x_i,y_i,_}. 2. Replace the element in test by the triplet from test2. I resorted to a loop after I decided that it would take me too much time to figure out a better, more elegant solution. Here is what I did: For[i=1,i<=Length[test2],i++, test = ReplacePart[test,test2[[i]], test//Position[#,{test2[[i]][[1]],test2[[i]][[2]],_}]& //Flatten]]; Thanks for any help. ------------------------------------------------------------------------------ Joel W. Cannon | (318)869-5160 Dept. of Physics | (318)869-5026 FAX Centenary College of Louisiana | P. O. Box 41188 | Shreveport, LA 71134-1188 |
- Follow-Ups:
- Re: Efficient way to merge lists--Programming help
- From: Reinhold Kainhofer <reinhold.kainhofer@kfunigraz.ac.at>
- Re: Efficient way to merge lists--Programming help
- From: Daniel Lichtblau <danl>
- Re: Efficient way to merge lists--Programming help