RE: Modification to Thread or MapThread
- To: mathgroup at smc.vnet.net
- Subject: [mg26400] RE: [mg26380] Modification to Thread or MapThread
- From: "David Park" <djmp at earthlink.net>
- Date: Wed, 20 Dec 2000 00:21:27 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Chris, Are you looking for something like this? V = Bond[v1, v2, v3]; container = {c}; Flatten[Outer[f, List @@ V, List @@ container]] {f[v1, c], f[v2, c], f[v3, c]} David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ > From: Chris Johnson [mailto:cjohnson at shell.faradic.net] To: mathgroup at smc.vnet.net > > Hello again, > > I am still playing around with making functions work over mixed vectors > and scalers for arguments and have run into a limitation of Thread and > MapThread. They don't handle different length lists well. The > Mathematica book mentions this and presents a work around, but it isn't > working for me. I was wondering what other peoples suggestions might be. > > I have a function that require 2 arguments: > f[container1_, container2_] > > The containers are like lists that generally should be kept > whole. Sometimes the containers may have a head like "Bond" othertimes > they are standard like "List". > > I have a vector V1 of objects of type container1 and a single object of > container2. > > I want to create the vector resulting from applying f over each > item in V1 and container2, or... > { f[ V1[[1]], container2], f[ V1[[2]], container2], ...} > > Best case and most intuitive to me is simply try f[V1, container2]. I > believe this would work if the function was "Listable", but it isn't. > Unfortunately, the way f is defined, this doesn't work. The solution so > far (Thanks to help from this list!) is to use the following syntax... > > f @@@ Transpose[V1, Table[container2, { Length[V1] } ] > > Is there a better way? Can I generalize the definitions of functions so > they can understand this type of syntax? Or even create my own function > which automagically threads vectors of objects and single objects? > > The main intent, I suppose, is to avoid generating a table that seems > unnecessary and feels sloppy. If avoiding the table creation isn't > possilble, getting it done behind the scenes would be an improvement to > me. A little paint over the duct tape, as it were. > > Thanks again. > > Chris > > > >