Mathematica 9 is now available
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: [mg69915] Re: [mg69865] Thread function over matrix elements?
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Wed, 27 Sep 2006 06:05:13 -0400 (EDT)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <200609260459.AAA01827@smc.vnet.net>
  • Reply-to: murray at math.umass.edu

If f is already a function that has attribute Listable, then you need 
only use:

   f[mat]

For example, Sin[mat].  And if f does not have attribute Listable, you 
could give it that attribute:

   SetAttributes[f, Listable]
   mat=Table[i+j,{i,0,2},{j,0,2}]
   f[mat]
{{f[0],f[1],f[2]},{f[1],f[2],f[3]},{f[2],f[3],f[4]}}

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

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305


  • Prev by Date: Re: why does FindMinimum have the attribute HoldAll?
  • Next by Date: "the sum of squares removed by fitting..."?
  • Previous by thread: Re: Thread function over matrix elements?
  • Next by thread: Re: Thread function over matrix elements?