Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

Modification to Thread or MapThread

  • To: mathgroup at smc.vnet.net
  • Subject: [mg26380] Modification to Thread or MapThread
  • From: Chris Johnson <cjohnson at shell.faradic.net>
  • Date: Sat, 16 Dec 2000 02:40:11 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

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




  • Prev by Date: Re: "?" to find symbols
  • Next by Date: Re: Bug in Package Graphics`Graphics` ?
  • Previous by thread: RE: bug with Compile ?
  • Next by thread: Re: Modification to Thread or MapThread