Re: MapThread over ragged arrays
- To: mathgroup at smc.vnet.net
- Subject: [mg83435] Re: MapThread over ragged arrays
- From: Bill Rowe <readnewsciv at sbcglobal.net>
- Date: Tue, 20 Nov 2007 03:55:10 -0500 (EST)
On 11/19/07 at 6:13 AM, bravi at cs.washington.edu (Ravi
Balasubramanian) wrote:
>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?
This seems to do what you want
In[3]:= MapThread[Thread[f[##]] &, {mat1, mat2}]
Out[3]= {{f[1, a], f[2, b]}, {f[2, b], f[3, c], f[4, d]}, {f[5, e],
f[6, f]}}
--
To reply via email subtract one hundred and four