Re: Elegant syntax for multiple conditional assignment?
- To: mathgroup at smc.vnet.net
- Subject: [mg54410] Re: [mg54337] Elegant syntax for multiple conditional assignment?
- From: Scott Hemphill <hemphill at hemphills.net>
- Date: Sun, 20 Feb 2005 00:08:22 -0500 (EST)
- Reply-to: hemphill at alumni.caltech.edu
- Sender: owner-wri-mathgroup at wolfram.com
On Sat, 19 Feb 2005, Bob Hanlon wrote: > old={a1,c1,x1,y1}; > > new={a2,c2,x2,y2}; > > cond={True,False,True,False}; > > {a,c,x,y} = If[#[[1]],#[[2]],#[[3]]]&/@ > Transpose[{cond,new,old}] > > {a2,c1,x2,y1} > > {a,c,x,y} = If[#[[1]],#[[2]],#[[3]]]&/@ > Thread[{cond,new,old}] > > {a2,c1,x2,y1} This isn't what I want. What I want is this: a1={1,2,3,4,5}; c1={6,7,8,9,10}; x1={11,12,13,14,15}; y1={16,17,18,19,20}; old={a1,c1,x1,y1}; a2={21,22,23,24,25}; c2={26,27,28,29,30}; x2={31,32,33,34,35}; y2={36,37,38,39,40}; new={a2,c2,x2,y2}; cond={True,False,True,False,True} (* Note: five elements *) What I want is code which takes old, new, and cond and makes this assignment: a={21,2,23,4,25}; c={26,7,28,9,30}; x={31,12,33,14,35}; y={36,17,38,19,40}; Scott -- Scott Hemphill hemphill at alumni.caltech.edu "This isn't flying. This is falling, with style." -- Buzz Lightyear