Re: logical indexing using more than one variable in a pure function
- To: mathgroup at smc.vnet.net
- Subject: [mg53368] Re: logical indexing using more than one variable in a pure function
- From: "Justin DSC Kaeser" <jastice at gmail.com>
- Date: Sat, 8 Jan 2005 02:39:39 -0500 (EST)
- References: <crkue3$akd$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
for your latter questions, it seems Map and MapThread will do just what you want. With x1 = {2, 3, 4, 5, 6}; x2 = {6, 5, 4, 3, 2}; the function # > 3 & /@ x1 will yield {False, False, True, True, True} and MapThread[#1 > #2 &, {x1, x2}] does an element-wise comparison for two equal-sized lists. Thread[(#1 > #2) &[x1, x2]] will do the same thing in this case So to select elements of x1 which are larger than the corresponding ones in x2 you could use BooleanSelect[x1, MapThread[(#1 > #2) &, {x1, x2}] ] This also produces that result, and more: Reap[MapThread[Sow[#1, #1 > #2] &, {x1, x2}]] see for yourself ;) Which is the more efficient option for large lists I do not know.