Re: compare 2-d array with vector [message #81545] |
Mon, 24 September 2012 08:30  |
Mark Piper
Messages: 198 Registered: December 2009
|
Senior Member |
|
|
On Monday, September 24, 2012 9:19:38 AM UTC-6, Craig Markwardt wrote:
>
> Yeah, I filed a support request on this several years ago, but no action so far.
>
Heinz & Craig,
This looks eminently reasonable. I'll look at getting it into the backlog today.
mp
|
|
|
Re: compare 2-d array with vector [message #81546 is a reply to message #81545] |
Mon, 24 September 2012 08:19   |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
On Monday, September 24, 2012 7:52:55 AM UTC-4, Heinz Stege wrote:
> On Mon, 24 Sep 2012 13:39:44 +0200, Heinz Stege wrote:
>
>
>
>> the use of the value_locate function is very helpful:
>
>>
>
>> subscripts=where(a eq b[value_locate(b,a)>0])
>
>>
>
>> Note that b must be sorted and must have 2 or more elements.
>
>
>
> AFAIK some IDL Developers are reading this newsgroup. Here is a
>
> request for an enhancement of the value_locate function:
>
>
>
> Please let value_locate return result=-long(a lt b[0]) instead of
>
> throwing an error message, if b has 1 element only.
Yeah, I filed a support request on this several years ago, but no action so far.
Craig
|
|
|
|
Re: compare 2-d array with vector [message #81548 is a reply to message #81547] |
Mon, 24 September 2012 04:39   |
Heinz Stege
Messages: 189 Registered: January 2003
|
Senior Member |
|
|
On Mon, 24 Sep 2012 00:32:17 -0700 (PDT), Danxia wrote:
> Hi all, I'm having problem when comparing a 2-d array with a given vector. For example, if giving a 2-d array
> a=[[1,1,1],
> [2,2,2],
> [3,3,3],
> [4,4,4]]
> and a vector b=[1,2],
> how can I get all the subscripts of array a that's equal to any element in vector b, which in this example is [0,1,2,3,4,5]. Please let me know if I failed to make this clear. Looking forward to any reply. Thank you very much!
Hi Danxia,
the use of the value_locate function is very helpful:
subscripts=where(a eq b[value_locate(b,a)>0])
Note that b must be sorted and must have 2 or more elements. ">0" may
be omitted, if a is an array (and you have not enabled the
STRICTARRSUBS compiler option).
Cheers, Heinz
|
|
|
Re: compare 2-d array with vector [message #81549 is a reply to message #81548] |
Mon, 24 September 2012 01:20   |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Monday, September 24, 2012 9:32:17 AM UTC+2, Danxia wrote:
> Hi all, I'm having problem when comparing a 2-d array with a given vector. For example, if giving a 2-d array
>
> a=[[1,1,1],
>
> [2,2,2],
>
> [3,3,3],
>
> [4,4,4]]
>
> and a vector b=[1,2],
>
> how can I get all the subscripts of array a that's equal to any element in vector b, which in this example is [0,1,2,3,4,5]. Please let me know if I failed to make this clear. Looking forward to any reply. Thank you very much!
Hi,
I think you should go for the histogram function. It is counter-intuitive at first, but is very fast and works well.
Example on how to start out:
IDL> a=[[1,1,1],[2,2,2],[4,4,4],[5,5,5]]
IDL> b = [2,4]
IDL> ha = histogram(a, REVERSE_INDICES=ra, OMAX=oMax, OMIN=oMin)
IDL> hb = histogram(b, MAX=oMax, MIN=oMin)
IDL> print, ha,hb
3 3 0 3 3
0 1 0 1 0
If you then loof for non zero values in the product of ha and hb then you can trace back the common values. If you use the reverse indices, you can find out where such values were in the original array.
Something like this (you have to make some extra controls for non existing matches and similar):
IDL> CommonPos = where(ha*hb)
IDL> FOR I=0,N_ELEMENTS(CommonPos)-1 DO PRINT, r[r[CommonPos[I]]:r[CommonPos[I]+1]-1]
3 4 5
6 7 8
Use array_indices if you want the positions in two dimensions.
Hope it helps,
Helder
|
|
|
Re: compare 2-d array with vector [message #82529 is a reply to message #81545] |
Mon, 17 December 2012 11:25   |
chris_torrence@NOSPAM
Messages: 528 Registered: March 2007
|
Senior Member |
|
|
On Monday, September 24, 2012 9:30:25 AM UTC-6, Mark Piper wrote:
> On Monday, September 24, 2012 9:19:38 AM UTC-6, Craig Markwardt wrote:
>
>>
>
>> Yeah, I filed a support request on this several years ago, but no action so far.
>
>>
>
>
>
> Heinz & Craig,
>
>
>
> This looks eminently reasonable. I'll look at getting it into the backlog today.
>
>
>
> mp
This is now fixed and will be in IDL 8.8.2. You can now pass a 1-element array or a scalar into value_locate.
-Chris
ExelisVIS
|
|
|
Re: compare 2-d array with vector [message #82604 is a reply to message #82529] |
Mon, 07 January 2013 02:59   |
Fabzi
Messages: 305 Registered: July 2010
|
Senior Member |
|
|
On 12/17/2012 08:25 PM, Chris Torrence wrote:
> This is now fixed and will be in IDL 8.8.2. You can now pass a 1-element array or a scalar into value_locate.
>
> -Chris
> ExelisVIS
Hi Chris,
While you are looking at VALUE_LOCATE, could you also look into this?
IDL> data = FINDGEN(10) & data[0] = !VALUES.F_NAN
IDL> p = VALUE_LOCATE(INDGEN(10), data) & print, p[0]
0
% Program caused arithmetic error: Floating illegal operand
IDL> p = VALUE_LOCATE(LINDGEN(10), data) & print, p[0]
-1
% Program caused arithmetic error: Floating illegal operand
IDL> p = VALUE_LOCATE(FINDGEN(10), data) & print, p[0]
-1
This was discussed in this thread:
https://groups.google.com/forum/?hl=fr&fromgroups=#!sear chin/comp.lang.idl-pvwave/fab/comp.lang.idl-pvwave/DBbUmnAaB Mc/kYdniU_d3koJ
Thanks!
Fab
|
|
|
Re: compare 2-d array with vector [message #82696 is a reply to message #82604] |
Mon, 07 January 2013 14:30  |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
On 1/7/13 4:59 AM, Fab wrote:
> On 12/17/2012 08:25 PM, Chris Torrence wrote:
>> This is now fixed and will be in IDL 8.8.2. You can now pass a
>> 1-element array or a scalar into value_locate.
>>
>> -Chris
>> ExelisVIS
>
> Hi Chris,
>
> While you are looking at VALUE_LOCATE, could you also look into this?
>
> IDL> data = FINDGEN(10) & data[0] = !VALUES.F_NAN
> IDL> p = VALUE_LOCATE(INDGEN(10), data) & print, p[0]
> 0
> % Program caused arithmetic error: Floating illegal operand
> IDL> p = VALUE_LOCATE(LINDGEN(10), data) & print, p[0]
> -1
> % Program caused arithmetic error: Floating illegal operand
> IDL> p = VALUE_LOCATE(FINDGEN(10), data) & print, p[0]
> -1
>
> This was discussed in this thread:
> https://groups.google.com/forum/?hl=fr&fromgroups=#!sear chin/comp.lang.idl-pvwave/fab/comp.lang.idl-pvwave/DBbUmnAaB Mc/kYdniU_d3koJ
>
>
> Thanks!
>
> Fab
>
What do you expect him to do? Our conclusion was that it's inherently
undefined, so there's not much point in asking for consistency.
-Jeremy.
|
|
|