Re: apparently I don't know how to use Map (or Apply or
- To: mathgroup at smc.vnet.net
- Subject: [mg77342] Re: [mg77290] apparently I don't know how to use Map (or Apply or
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Thu, 7 Jun 2007 03:43:36 -0400 (EDT)
- Reply-to: hanlonr at cox.net
m = {{0.098, 0.951, 0.954}, {0.509, 0.914, 0.487}};
Table[m[[i, i]], {i, Length[m]}]
{0.098,0.914}
i = 1; #[[i++]] & /@ m
{0.098,0.914}
New in v6:
Diagonal[m]
{0.098,0.914}
Bob Hanlon
---- 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..
>
>