Re: apparently I don't know how to use Map (or Apply or MapThread)

• To: mathgroup at smc.vnet.net
• Subject: [mg77359] Re: apparently I don't know how to use Map (or Apply or MapThread)
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Thu, 7 Jun 2007 03:52:32 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <f4676i\$1n3\$1@smc.vnet.net>

```dbsearch04 at yahoo.com wrote:
> I started with this:
>
> m = {{0.098, 0.951, 0.954}, {0.509, 0.914, 0.487}}
>
> I tried to do this
>
> Table[#[[i, i]], {i, Length[#]}] & /@ m
>
> It does not work, but this works
>
> Diag := Function[x, Table[x[[i, i]], {i, Length[x]}]]; Diag[m]
>
> !@#\$%^&*(
>
> Can anyone tell me why? I also tried: Apply, MapThread,
> DiagonalMatrix, TakeMatrix, adding () around the pure function...
>
> I know that this is a simple problem. Would Evaluate help?
>
> TIA.
>
> Regards..

Map goes one level to deep with respect to what you try to achieve. The
following will work as expected.

In[1]:= m = {{0.098, 0.951, 0.954}, {0.509, 0.914, 0.487}};
Table[#1[[i, i]], {i, Length[#1]}] & @ m
Table[#1[[i, i]], {i, Length[#1]}] & [m]

Out[2]= {0.098, 0.914}

Out[3]= {0.098, 0.914}

Regards
Jean-Marc

```

• Prev by Date: Re: apparently I don't know how to use Map (or Apply or MapThread)
• Next by Date: Re: Mapping a pure function with 2 conponents.
• Previous by thread: Re: apparently I don't know how to use Map (or Apply or MapThread)
• Next by thread: Re: apparently I don't know how to use Map (or Apply or MapThread)