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

RE: Newbie question: pairswise function application

  • To: mathgroup at smc.vnet.net
  • Subject: [mg23868] RE: [mg23857] Newbie question: pairswise function application
  • From: "David Park" <djmp at earthlink.net>
  • Date: Thu, 15 Jun 2000 00:51:07 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com


> -----Original Message-----
> From: Sidney Cadot [mailto:sidney at janis.pds.tudelft.nl]
To: mathgroup at smc.vnet.net
 
> Hi,
> 
> Wandering through the 1500-odd pages of the Mathematica book, I can't
> find the solution to the following rather silly problem:
> 
> I have a list L consisting of (a lot of) integers, and I want to apply a
> function f to all pairs of numbers; furthermore, I don't want to
> calculate both f[a,b] and f[b,a]:
> 
>   L = {1,5,19,100};
> 
> ... and I want:
> 
>   { f[1,5], f[1,19], f[1,100], f[5,19], f[5,100], f[19,100] }
> 
> Can anyone please tell me how to do this? I'd prefer a smart solution
> (i.e., not just generating all pairs, then throwing away a lot of them)
> since my lists tend to get rather large.
> 
> Thanks in advance,
> 
>   Sidney Cadot
>   sidney at janis.pds.twi.tudelft.nl
> 

Sidney,

This is one method:

li = {1, 5, 9, 100};

Flatten[Table[f[li[[i]], li[[j]]], 
   {i, 1, Length[li] - 1}, {j, i + 1, Length[li]}]]
{f[1, 5], f[1, 9], f[1, 100], f[5, 9], f[5, 100], f[9, 100]}

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/ 



  • Prev by Date: Re: Linking with C++
  • Next by Date: Sums and Products: Compact Notation and Differentiation
  • Previous by thread: Re: Newbie question: pairswise function application
  • Next by thread: Re: Newbie question: pairswise function application