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
- References:
- Thread function over matrix elements?
- From: "ben" <benjamin.friedrich@gmail.com>
- Thread function over matrix elements?