MathGroup Archive 2006

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

Search the Archive

Re: Thread function over matrix elements?


Ben,
you must say "only at level 2, please", i.e.  Map[f,mat,{2}], not  
"levels up to 2" Map[f,mat,2].

Level specifications are described in Sect. A.3.6 of the Mathematica  
book.

Adriano Pascoletti


On 26 set 2006, at 06: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
>


  • Prev by Date: Re: Mapping Functions That Take More Than One Argument
  • Next by Date: Re: Thread function over matrix elements?
  • Previous by thread: Thread function over matrix elements?
  • Next by thread: Re: Thread function over matrix elements?