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: [mg77387] Re: [mg77290] apparently I don't know how to use Map (or Apply or MapThread)
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Thu, 7 Jun 2007 04:07:12 -0400 (EDT)
  • Organization: Deep Space Corps of Engineers
  • References: <32820206.1181130858075.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

m has two dimensions, but its elements (each is a List) only have one  =

dimension.

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

{{0.098, 0.951, 0.954}, {0.509, 0.914, 0.487}}

{0.098, 0.914}

But there's a built-in function for this, too:

Diagonal@m

{0.098, 0.914}

Bobby

On Wed, 06 Jun 2007 06:17:01 -0500, <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..
>
>
>



-- =

DrMajorBob at bigfoot.com


  • Prev by Date: Re: apparently I don't know how to use Map (or Apply or MapThread)
  • Next by Date: Re: Re: Best practice for Mathematica package development
  • Previous by thread: Re: apparently I don't know how to use Map (or Apply or MapThread)
  • Next by thread: Line-joins and line-caps in Mathematica 6