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

Re: Modification to Thread or MapThread

  • To: mathgroup at smc.vnet.net
  • Subject: [mg26404] Re: [mg26380] Modification to Thread or MapThread
  • From: "Carl K. Woll" <carlw at u.washington.edu>
  • Date: Wed, 20 Dec 2000 00:21:30 -0500 (EST)
  • References: <200012160740.CAA05162@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Chris,

One possibility is to make the function Listable. Alternatively, a simpler
solution than the one you proposed is the following

f[#,container2]&/@V1

Carl Woll
Physics Dept
U of Washington

----- Original Message -----
From: "Chris Johnson" <cjohnson at shell.faradic.net>
To: mathgroup at smc.vnet.net
Subject: [mg26404] [mg26380] Modification to Thread or MapThread


> 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: Modification to Thread or MapThread
  • Next by Date: Re: physical colors and Mathematica colors
  • Previous by thread: Modification to Thread or MapThread
  • Next by thread: Re: Modification to Thread or MapThread