       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:= Map[Function[x, 2], {{1, 2}, {1, 2}}, 2]

>Out= {2, 2}

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

>Out= {{2, 2}, {2, 2}}

What were you expecting? Note

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

Out= 2

since this function replaces any argument with 2. But

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

Out= {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:= Map[Function[x, 2], {{1, 2}, {1, 2}}, {2}]

Out= {{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