Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: InputStream in version 3 vs version 4

  • To: mathgroup at smc.vnet.net
  • Subject: [mg18794] Re: [mg18773] InputStream in version 3 vs version 4
  • From: "Wolf, Hartmut" <hwolf at debis.com>
  • Date: Thu, 22 Jul 1999 08:19:18 -0400
  • Organization: debis Systemhaus
  • References: <199907200533.BAA11600@smc.vnet.net.>
  • Sender: owner-wri-mathgroup at wolfram.com

Dear Luci

ELLIS, Luci schrieb:
> 
--x---x---x-- 
> 
> Failing this, can anyone suggest a robust way to turn a list of functions
> and a matrix of data into a matrix where the elements of each row are the
> elements of the original matrix transformed by the corresponding function?
> 
> That is:
> functions= {f[#]&, g[#]&, h[#]&}
> data = {{data[1,1],data[1,2],data[1,3]},{data[2,1],data[2,2],data[2,3},
> {data[3,1],data[3,2],data[3,3},
> {data[4,1],data[4,2],data[4,3]},{data[5,1],data[5,2],data[5,3}}
> {
> output= {f[data[1,1]], g[data[1,2]], h[data[1,3]]}, {f[data[2,1]],
> g[data[2,2]], h[data[2,3]]}, {f[data[3,1]], g[data[3,2]], h[data[3,3]]},
> {f[data[4,1]], g[data[4,2]], h[data[4,3]]}, {f[data[5,1]], g[data[5,2]],
> h[data[5,3]]},
> 
If we Map at level 0, we get our tool:

In[1]:= Map[f,x,{0}]
Out[1]= f[x]

Operating on Lists of functions and arguments (generalisation of inner
product)

In[2]:= Inner[Map[#1,#2,{0}]&,{f,g,h},{1,2,3},List]
Out[2]= {f[1],g[2],h[3]}

So now we can Map that over your List (of argument records)

In[3]:= funs={f,g,h};
In[4]:= data=Array[dd,{5,3}]
Out[4]=
{{dd[1,1],dd[1,2],dd[1,3]},
 {dd[2,1],dd[2,2],dd[2,3]},
 {dd[3,1],dd[3,2],dd[3,3]},
 {dd[4,1],dd[4,2],dd[4,3]},
 {dd[5,1],dd[5,2],dd[5,3]}}

In[5]:= Inner[Map[#1,#2,{0}]&,funs,#,List]& /@ data
Out[5]=
{{f[dd[1,1]],g[dd[1,2]],h[dd[1,3]]},
 {f[dd[2,1]],g[dd[2,2]],h[dd[2,3]]},
 {f[dd[3,1]],g[dd[3,2]],h[dd[3,3]]},
 {f[dd[4,1]],g[dd[4,2]],h[dd[4,3]]},
 {f[dd[5,1]],g[dd[5,2]],h[dd[5,3]]}}

For your case, you may conveniently define

In[23]:= inapp[funs_]:=Inner[Map[#1,#2,{0}]&,funs,#,List]&

and work with the expression

In[24]:=
inapp[funs]/@data
Out[24]=
{{f[dd[1,1]],g[dd[1,2]],h[dd[1,3]]},
 {f[dd[2,1]],g[dd[2,2]],h[dd[2,3]]},
 {f[dd[3,1]],g[dd[3,2]],h[dd[3,3]]},
 {f[dd[4,1]],g[dd[4,2]],h[dd[4,3]]},
 {f[dd[5,1]],g[dd[5,2]],h[dd[5,3]]}}

kind regards, hw



  • Prev by Date: Re: How can I plot the region satisfying an inequality?
  • Next by Date: complex-valued expression not simplifying completely (was: ARghh!!)
  • Previous by thread: InputStream in version 3 vs version 4
  • Next by thread: Re: InputStream in version 3 vs version 4