Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

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)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg77371] Re: apparently I don't know how to use Map (or Apply or MapThread)
  • From: mwjdavidson at googlemail.com
  • Date: Thu, 7 Jun 2007 03:58:52 -0400 (EDT)
  • References: <f4676i$1n3$1@smc.vnet.net>

On Jun 6, 1:52 pm, dbsearc... 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
>
I take it you are trying to extract the diagonal elements from your
matrix m ?

If so why not use

Diagonal[m]

which gives you the same result as your function definition. Your
example using map does not work because
map iterates over 1 row at a time. As each of your rows is a 1 x three
elements long list #[[i,i]] cannot exist for
i > 1.

malcolm

> 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: apparently I don't know how to use Map (or Apply or MapThread)
  • 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)