MathGroup Archive 2007

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

Search the Archive

Re: MapThread over ragged arrays

  • To: mathgroup at
  • Subject: [mg83674] Re: MapThread over ragged arrays
  • From: Vince Virgilio <blueschi at>
  • Date: Wed, 28 Nov 2007 05:28:22 -0500 (EST)
  • References: <fhrrbf$583$>

On Nov 19, 6:17 am, Ravi Balasubramanian <br... at>
> 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


I've worked around this design of MapThread with Join, Map, then

First Join mat1 and mat2 at level 2. Then Map an augmented f over the
result. Let the new f first split/partition its list argument into two
equal halves (1st and 2nd half, using Partition[#, Length[arg]/2]&),
and thread its old self over the result. If time permits, I'll post
code later; it looks quite clean.

Vince Virgilio

  • Prev by Date: Controlling evaluation
  • Next by Date: Re: Mathematica 6.0 Desperation
  • Previous by thread: Re: MapThread over ragged arrays
  • Next by thread: Re: MapThread over ragged arrays