comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Unique combinations from a 1d array
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Unique combinations from a 1d array [message #37699 is a reply to message #37625] Fri, 16 January 2004 01:43 Go to previous messageGo to previous message
Chris Lee is currently offline  Chris Lee
Messages: 101
Registered: August 2003
Senior Member
In article <1b881b7a.0401150857.37594317@posting.google.com>, "Darren"
<dapoulio@sympatico.ca> wrote:


> <big snip>
>> return, val[where(y gt 0)]
<snip>

> The total combinations can be found using: n!/(n-p)!*p!
> Where n is the total number of array elements and p is the size of the
> desired combination in my case p = 2. Both of the code examples given
> by Chris do this much more efficiently than what I posted. For 3000
> cases, the matrix approach came in at 0.614s and the loop approach at
> 2.414s on my 2.4 GHz Pentium. However, I believe there was a typo for
> the matrix approach on the last line which should read �
> return, val[where(mask gt 0)]' to give the array of paired differences.
> Thanks again,
> Darren

Ah,
For the total combinations I just used sum(1..N), which could be replaced
with... (doh, hindsight) N(N-1)/2. Which is the same as yours for p=2 (but
without the 3000 ! )

The typo in the matrix approach....that's what happens when I use
different variables in my IDL code to my newsgroup post :)

Chris.
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: IDL vs Direct3D, OpenGL
Next Topic: Throwing objects to Virtual Machine in Unix

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Oct 12 04:37:30 PDT 2025

Total time taken to generate the page: 1.04103 seconds