Array comparison [message #32357] |
Tue, 01 October 2002 15:08  |
Sean Raffuse
Messages: 46 Registered: July 2001
|
Member |
|
|
Hello,
I would like to compare two arrays of different size. What I want to know
is if the two arrays share ANY of the same values, regardless of index.
e.g.
Array1 = [1,2,3,4,5]
Array2 = [5,6,7]
Comparing these two arrays should return true because they both have the
value 5.
I know I could do this in a loop, but I need the speed and I'm sure IDL can
do this in one line. I'm just not sure how.
Thanks,
Sean Raffuse
|
|
|
Re: Array Comparison [message #49462 is a reply to message #32357] |
Wed, 26 July 2006 08:42  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
ChristopherFlorio@gmail.com writes:
> I am looking for a simple comparison tool such with an array of
> consecutive numbers (i.e. [0,1,2,3,4,5,6,7,8,9]) and array of numbers
> included in that array (i.e. [0,5,9]) I can calculate the matrix of
> "left-over" items (i.e [1,2,3,4,6,7,8]). This can be either array of
> integers or strings. Any Suggestions?
You could use my set manipulator. For example, in your A AND NOT(B)
case,
IDL> a = [0,1,2,3,4,5,6,7,8,9]
IDL> b = [0,5,9]
IDL> print, cmset_op(a, 'AND', /NOT2, b)
1 2 3 4 6 7 8
or
IDL> print, cmset_op(a, 'XOR', b)
1 2 3 4 6 7 8
Hope that helps!
Craig
P.S. Please see http://cow.physics.wisc.edu/~craigm/idl/ under "Array/Set"
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|