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

Home » Public Forums » archive » histogram & reverse_indices
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: histogram & reverse_indices [message #30220 is a reply to message #30071] Tue, 09 April 2002 13:47 Go to previous message
Wayne Landsman is currently offline  Wayne Landsman
Messages: 117
Registered: January 1997
Senior Member
Ken Mankoff wrote:

>
> I have a 2D array made up of n quadruplets. Ex:
> array =[[1,1,1,2], $
> [1,1,1,1], $
> [3,4,3,2], $
> [3,3,0,0], $
> [5,5,0,5]]
>
> I want my algorithm to do the following: Return the index of all the
> quadruplets that have at least 3 out of 4 numbers equal to each other
> (i.e. for the above array, it should return [0,1,4]

Here's a non-loop solution for the specific case, although it is a
solution that is difficult to generalize, and which may be less
understandable and slower than simply using a loop.

The idea is that if 3 out of 4 numbers are equal to each other, then that
number is either the minimum or the maximum of the quadruplet. So we
first get the min and max of each quadruplet.

amin = min(array,dimen=1,max=amax) ;V5.5 needed

Now reform/rebin the min and max vectors into a 2d arrays

amax = rebin(reform(amax,1,5),4,5)
amin = rebin(reform(amin,1,5),4,5)

Now find which values in the array are equal to either the minimum or the
maximum. Total along rows
to determine if 3 or more values in a quadruplet meet this condition:

print,where( (total((array EQ amin),1) GE 3) or $
(total((array EQ amax),1) GE 3))

---> [0,1,4]

--Wayne
landsman@mpb.gsfc.nasa.gov
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: basic soubt with fltarr
Next Topic: Ascertaining Keyword Parameters

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

Current Time: Wed Oct 08 12:52:38 PDT 2025

Total time taken to generate the page: 0.00434 seconds