Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

Re: strange behavior with Map

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116401] Re: strange behavior with Map
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Sun, 13 Feb 2011 03:07:39 -0500 (EST)

On 2/12/11 at 5:20 AM, robertr at math.uh.edu (Robert Rosenbaum) wrote:

>This doesn't seem right:

>In[181]:= Map[Function[x, 2], {{1, 2}, {1, 2}}, 2]

>Out[181]= {2, 2}

>In[180]:= Map[Function[x, 0 x + 2], {{1, 2}, {1, 2}}, 2]

>Out[180]= {{2, 2}, {2, 2}}

What were you expecting? Note

In[52]:= Function[x, 2][{1, 2}]

Out[52]= 2

since this function replaces any argument with 2. But

In[53]:= Function[x, 0 x + 2][{1, 2}]

Out[53]= {2,2}

since this function multiplies the list by 0 then adds 2 which
means the result will have the same number of elements as the
input when the input is a list.

Perhaps you meant to map the function to only level 2 rather
than levels 1 through 2? That is

In[54]:= Map[Function[x, 2], {{1, 2}, {1, 2}}, {2}]

Out[54]= {{2, 2}, {2, 2}}



  • Prev by Date: Re: solution of equation
  • Next by Date: Re: solution of equation
  • Previous by thread: Re: strange behavior with Map
  • Next by thread: Re: strange behavior with Map