Re: simple problem with Map?!?
- To: mathgroup at smc.vnet.net
- Subject: [mg49513] Re: simple problem with Map?!?
- From: "Curt Fischer" <crf3 at po.cwru.edu>
- Date: Thu, 22 Jul 2004 02:46:05 -0400 (EDT)
- References: <cdljfp$867$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Relishguy wrote: > I do not understand why the last evaluation ends up screwed: > > In[1]:= d0 = {30,60,180,60,30}; > > In[2]:= tt = Plus @@ d0 > Out[2]= 360 > > In[3]:= pp = N[d0 / tt] > Out[3]= {0.0833333,0.166667,0.5,0.166667,0.0833333} > > In[4]:= ppp = N[d0 / (Plus @@ d0)] > Out[4]= {0.0833333,0.166667,0.5,0.166667,0.0833333} > > In[5]:= pppp = N[# / (Plus @@ #)]& /@ d0 > Out[5]= {1.,1.,1.,1.,1.} > > Can anyone explain this simply? Do I need Hold[] or Evaluate[] > somewhere? No. Right now you are Mapping your entire pure function N[#,(Plus@@#)]& onto the list d0. Thus, this entire function is first applied to the first element in d0: N[30/(Plus@@30)], which gives 1. Next, the entire pure function is applied to the second element of d0, giving 1. again, and so on. To get what you want, how about ppppp = N[#/(Plus @@ #)] &[d0] ??? -- Curt Fischer