Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*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 2006

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

Search the Archive

Re: Lists of all values of a two-variable function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64750] Re: Lists of all values of a two-variable function
  • From: albert <awnl at arcor.de>
  • Date: Thu, 2 Mar 2006 06:47:37 -0500 (EST)
  • References: <du3vcn$mjd$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

José Carlos Santos wrote:

> Hi all,
> 
> I would like to do this: given a function _f_ in two variables and two
> lists l1 and l2, to get the list of all values f[a,b] with _a_ in l1 and
> _b_ in l2, with all duplicated values removed. How do I do that?
> 
> The closest thing that I am able to do is:
> 
> Table[f[l1[[i]],l2[[j]]],{i,1,Length[l1]},{j,1,Length[l2]}]
> 
> but, of course:
> 
> 1) what I get is a list of lists;
> 
> 2) I eventually get duplicated values.
> 
> Best regards,
> 
> Jose Carlos Santos


try to wrap Flatten (get rid of the extra lists) and Union (removes
dublicates) around your Table:

Union[Flatten[Table[...],1]]

or try this, which is somewhat shorter and probably faster, too:

Union[Flatten[Outer[f, l1, l2],1]]

hth,

albert


  • Prev by Date: Re: Lists of all values of a two-variable function
  • Next by Date: Re: Lists of all values of a two-variable function
  • Previous by thread: Re: Lists of all values of a two-variable function
  • Next by thread: Re: Lists of all values of a two-variable function