Re: simple problem with Map?!?

• To: mathgroup at smc.vnet.net
• Subject: [mg49563] Re: [mg49480] simple problem with Map?!?
• From: DrBob <drbob at bigfoot.com>
• Date: Fri, 23 Jul 2004 06:00:28 -0400 (EDT)
• References: <200407211040.GAA07884@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Study the results of this code:

d0 = {30, 60};
pppp = N[#/(Plus @@ #)] & /@ d0 // Trace

(snip)

The pure function N[#/(Plus @@ #)] & is applied to each element of d0 (30 and 60) separately.

Plus@@30 is 30, so we get N[30/30], which is N[1], and that's 1. That's what happens for every element of d0, so the result is {1.,1.}.

Probably what you want is just:

N[d0/Tr@d0]

{0.333333,0.666667}

Bobby

On Wed, 21 Jul 2004 06:40:32 -0400 (EDT), Relishguy <relishguy at pluggedin.org> 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?
>
> TIA.
>
> Regards..
>
>
>

--
DrBob at bigfoot.com
www.eclecticdreams.net

```

• Prev by Date: New GUIKit for Mathematica
• Next by Date: [Bug] Transpose is broken for empty SparseArrays
• Previous by thread: Re: simple problem with Map?!?
• Next by thread: Re: simple problem with Map?!?