Re: MapThread over ragged arrays
- To: mathgroup at smc.vnet.net
- Subject: [mg83432] Re: [mg83388] MapThread over ragged arrays
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Tue, 20 Nov 2007 03:53:36 -0500 (EST)
- Reply-to: hanlonr at cox.net
mat1 = {{1, 2}, {2, 3, 4}, {5, 6}}; mat2 = {{a, b}, {b, c, d}, {e, f}}; f @@@ Thread[#] & /@ Transpose[{mat1, mat2}] {{f[1, a], f[2, b]}, {f[2, b], f[3, c], f[4, d]}, {f[5, e], f[6, f]}} Bob Hanlon ---- Ravi Balasubramanian <bravi 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 >