[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: findng array[3] in array[3,n]



tbowers wrote:
> 
> If I have
> 
> a=[ $
>  [0,1,2], $
>  [3,4,5], $
>  [6,7,8]]
> 
> b=[3,4,5]
> 
> how do I find where in a is the row vector b? The answer should
> be 1, the 2nd row of a. I've tried many
> permutations of where(), but I just don't get it. The only way I
> can get an answer is to loop through the rows till i find a match.
> What I'm really tryin' to do is to find a color in a color table,
> e.g. load RAINBOW color table, (loadct,13) then identify
> where a color is. For the color that's listed 6th in the color table
> (an almost black) that'd be the 5th row index. Like:

> So, does anyone know see an elegant solution to this problem??

I can't say it's elegant, but:

where(total(rebin(b,n_elements(b),(size(a,/DIMENSIONS))[1],/SAMP) eq
a,1) eq n_elements(b))

The rule is, when comparing arrays, you must expand the smaller to the
size of the larger.

JD