Services & Resources / Wolfram Forums
MathGroup Archive
*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
  • Subject: [mg69915] Re: [mg69865] Thread function over matrix elements?
  • From: Murray Eisenberg <murray at>
  • Date: Wed, 27 Sep 2006 06:05:13 -0400 (EDT)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <>
  • Reply-to: murray at

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


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

   SetAttributes[f, Listable]

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