MathGroup Archive 2007

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

Search the Archive

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


Hi,

you mean

Table[#[[i, i]], {i, Length[#]}] &@ m

or with (Mathematica 6.0)*

Diagonal[m]

or if you whant to use Map*[]

Reap[MapIndexed[If[Equal @@ #2, Sow[#1]] &, m, {2}]][[2, 1]]

or

First /@ MapIndexed[RotateLeft[#1, #2[[1]] - 1] &, m]

or

MapIndexed[ #1[[#2[[1]]]] &, m]

or
MapIndexed[ First @ Take[#1, #2] &, m]

Regards
   Jens

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..
> 
> 


  • Prev by Date: Re: Mapping a pure function with 2 conponents.
  • Next by Date: Re: apparently I don't know how to use Map (or Apply or MapThread)
  • 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)