From: Bob Hanlon on 19 Mar 2010 07:45 expr = b[a[c], a[c], a[d]]; lst = {e, f, g}; Head[expr] @@ Head[expr[[1]]] /@ lst b[a[e], a[f], a[g]] More generally, Inner[Head[#1][#2] &, List @@ expr, lst, Head[expr]] b[a[e], a[f], a[g]] Bob Hanlon ---- divisor <congruentialuminaire(a)yahoo.com> wrote: ============= Hello mathGroup: I have an expression like this: b[ a[c], a[c], a[d]] a list like this: {e,f,g} I want to end up with b[ a[e], a[f], a[g]] I think of this as interleaving a list into an expression, but all my tries with ./,.//,MapIndexed[],MapAt[], Partition[Riffle[]] have come to no avail. Any help on this is greatly appreciated. Roger Williams Franklin Laboratory http://www.youtube.com/congruentlight
From: rafscipio on 19 Mar 2010 07:45 On 19 Mar, 08:47, divisor <congruentialumina...(a)yahoo.com> wrote: > Hello mathGroup: > > I have an expression like this: > > b[ a[c], a[c], a[d]] > > a list like this: > > {e,f,g} > > I want to end up with > > b[ a[e], a[f], a[g]] > > I think of this as interleaving a list into an expression, but all my > tries with ./,.//,MapIndexed[],MapAt[], Partition[Riffle[]] have come > to no avail. > > Any help on this is greatly appreciated. > > Roger Williams > Franklin Laboratoryhttp://www.youtube.com/congruentlight Hi, here is a way: In[1]:= x = b[a[c], a[c], a[d]]; In[2]:= y = {e, f, g}; In[3]:= Do[x[[i, 1]] = y[[i]], {i, 3}]; x Out[3]= b[a[e], a[f], a[g]] Scipione.
From: rafscipio on 20 Mar 2010 03:46 On 19 Mar, 08:47, divisor <congruentialumina...(a)yahoo.com> wrote: > Hello mathGroup: > > I have an expression like this: > > b[ a[c], a[c], a[d]] > > a list like this: > > {e,f,g} > > I want to end up with > > b[ a[e], a[f], a[g]] > > I think of this as interleaving a list into an expression, but all my > tries with ./,.//,MapIndexed[],MapAt[], Partition[Riffle[]] have come > to no avail. > > Any help on this is greatly appreciated. > > Roger Williams > Franklin Laboratoryhttp://www.youtube.com/congruentlight Another variation: In[1]:= x = b[a[c], a[c], a[d]]; In[2]:= y = {e, f, g}; In[3]:= Evaluate[List@@x[[All, 1]]] = y; x Scipione
From: Ray Koopman on 20 Mar 2010 04:02 On Mar 19, 4:44 am, Ray Koopman <koop...(a)sfu.ca> wrote: > On Mar 19, 12:47 am, divisor <congruentialumina...(a)yahoo.com> wrote: >> Hello mathGroup: >> >> I have an expression like this: >> >> b[ a[c], a[c], a[d]] >> >> a list like this: >> >> {e,f,g} >> >> I want to end up with >> >> b[ a[e], a[f], a[g]] >> >> I think of this as interleaving a list into an expression, but all my >> tries with ./,.//,MapIndexed[],MapAt[], Partition[Riffle[]] have come >> to no avail. >> >> Any help on this is greatly appreciated. >> >> Roger Williams >> Franklin Laboratoryhttp://www.youtube.com/congruentlight > > In[1]:= b @@ a /@ {e,f,g} > > Out[1]= b[a[e],a[f],a[g]] Sorry, I misunderstood (oversimplified) the question. Here is the answer to a slightly more general question. In[1]:= expr = b[ a[x], c[y], d[z] ]; list = {e, f, g}; Head[expr] @@ MapThread[Head[#1][#2]&,{List@@expr,list}] Out[3]= b[ a[e], c[f], d[g] ]
From: rafscipio on 20 Mar 2010 04:03 On 19 Mar, 08:47, divisor <congruentialumina...(a)yahoo.com> wrote: > Hello mathGroup: > > I have an expression like this: > > b[ a[c], a[c], a[d]] > > a list like this: > > {e,f,g} > > I want to end up with > > b[ a[e], a[f], a[g]] > > I think of this as interleaving a list into an expression, but all my > tries with ./,.//,MapIndexed[],MapAt[], Partition[Riffle[]] have come > to no avail. > > Any help on this is greatly appreciated. > > Roger Williams > Franklin Laboratoryhttp://www.youtube.com/congruentlight Just to add another way: In[1]:= x = b[a[c], a[c], a[d]]; In[2]:= y = {e, f, g}; In[3]:= Inner[(#1[#2]) &, Level[x[[All, 0]], 1], y, Head@x] Scipione
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: blobs functions Next: Function construction and also symmetric matrices |