MathGroup Archive 2007

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

Search the Archive

Re: MapThread over ragged arrays

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83447] Re: MapThread over ragged arrays
  • From: Mark Fisher <particlefilter at gmail.com>
  • Date: Wed, 21 Nov 2007 02:39:12 -0500 (EST)
  • References: <fhrrbf$583$1@smc.vnet.net>

On Nov 19, 6:17 am, Ravi Balasubramanian <br... at cs.washington.edu>
wrote:
> Hello people,
>
> I have two matrices that are ragged.
>
> mat1  = {{1, 2}, {2, 3, 4}, {5, 6}}
> mat2 = {{a, b}, {b, c, d}, {e, f}}
>
> I have to Map a function f at level 2.  So that I have
>
> {
> {f[1,a],f[2,b]},
> {f[2,b], f[3,c], f[4,d]},
> {f[5,e],f[6,f]},
>
> }
>
> MapThread seems to thread only over full arrays, and so I cannot thread
> over level {2}.  I know I can I do this using two MapThreads (each at
> level 1), but that seems unnecessary.  Thread seems to apply the head to
> each value, and if the head does not match, the value is repeated (which
> might not be necessary).  Seems like a simple thing to do.  Any ideas?
>
> Ravi
> Univ. of Washington
> Seattle, WA

Hi,

This seems to work too:

MapThread[f, #] & /@ Transpose[{mat1, mat2}]

--Mark



  • Prev by Date: Re: Plotting Points with Labels
  • Next by Date: Re: Scalars Instead of Lists with One Element
  • Previous by thread: Re: MapThread over ragged arrays
  • Next by thread: Re: MapThread over ragged arrays