Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: Thread function over matrix elements?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69881] Re: [mg69865] Thread function over matrix elements?
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Tue, 26 Sep 2006 05:21:29 -0400 (EDT)

On 26 Sep 2006, at 13:59, ben wrote:

> Dear all,
>
> how do I thread a function over all elements of a matrix?
> This piece of code works, but I doubt its the way i am supposed to do
> this
>
> mat=Table[i+j,{i,0,2},{j,0,2}]
>
> Map[Map[f[#]&,#]&,mat]
>
> I tried
>
> Map[f[#]&,mat,2]
> Apply[f[#]&,mat,2]
> Thread[f[mat]]
>
> but they give weird results.
>
> Cheers
> Ben
>



Map[f, mat, {2}]

Note the difference between the level specification {2} and 2 (as you  
had originally).

Andrzej Kozlowski


  • Prev by Date: Program to calculate rational function with imbedded continued fraction
  • Next by Date: How to remove just the outermost braces of a list?
  • Previous by thread: Re: Thread function over matrix elements?
  • Next by thread: Re: Thread function over matrix elements?