Re: How to extract a datarange from a multidimensional array? [message #42350] |
Fri, 28 January 2005 08:22 |
JD Smith
Messages: 850 Registered: December 1999
|
Senior Member |
|
|
On Fri, 28 Jan 2005 11:33:05 +0100, David Lopez Pons wrote:
> aeon@gmx.de wrote:
>
>> Hi,
>>
>> i have following example data:
>> x = [0,5,2,6,5,3,9]
>> y = [1,5,7,4,3,4,8]
>>
>> to get the (x,y)-pairs in a special range i used the following:
>> points = WHERE((x LE (5))AND(x GE (2))AND(y LE (7))AND(y GE (3)),count)
>>
>> Because i accept now the fact, that IDL works faster with array
>> operations instead of for-loops ;)
>> i want to do the following:
>> xy=[[0,5,2,6,5,3,9],[1,5,7,4,3,4,8]]
>>
>> points=???
>>
>> i tried
>> points= WHERE ((xy LE[5,7])AND(xy GE[2,3]),count)
>> but this dont works for me.
>>
>> I know the solution is for sure simple one, but i cant find it.
>> THX for every idea.
>>
>>
>>
> May be this is enough for you:
>
> IDL> xy=[[0,5,2,6,5,3,9],[1,5,7,4,3,4,8]]
> IDL> points2 = WHERE((xy[*,0] LE (5))AND(xy[*,0] GE (2))AND(xy[*,1] LE
> (7))AND(xy[*,1] GE (3)),count)
> IDL> print,points2
> 1 2 4 5
This will actually be slower than the original method proposed,
keeping X & Y separate, since essentially you're doing the same amount
of comparison work, but must also generate subscripting indices to
divide the xy array back into x and y 4 times. Check out
http://www.dfanning.com/misc_tips/submemory.html for more info on why
higher-order subscripting can get you into trouble.
JD
|
|
|
|
Re: How to extract a datarange from a multidimensional array? [message #42359 is a reply to message #42358] |
Fri, 28 January 2005 02:33  |
David Lopez Pons
Messages: 8 Registered: July 2003
|
Junior Member |
|
|
aeon@gmx.de wrote:
> Hi,
>
> i have following example data:
> x = [0,5,2,6,5,3,9]
> y = [1,5,7,4,3,4,8]
>
> to get the (x,y)-pairs in a special range i used the following:
> points = WHERE((x LE (5))AND(x GE (2))AND(y LE (7))AND(y GE (3)),count)
>
> Because i accept now the fact, that IDL works faster with array
> operations instead of for-loops ;)
> i want to do the following:
> xy=[[0,5,2,6,5,3,9],[1,5,7,4,3,4,8]]
>
> points=???
>
> i tried
> points= WHERE ((xy LE[5,7])AND(xy GE[2,3]),count)
> but this dont works for me.
>
> I know the solution is for sure simple one, but i cant find it.
> THX for every idea.
>
>
>
May be this is enough for you:
IDL> xy=[[0,5,2,6,5,3,9],[1,5,7,4,3,4,8]]
IDL> points2 = WHERE((xy[*,0] LE (5))AND(xy[*,0] GE (2))AND(xy[*,1] LE
(7))AND(xy[*,1] GE (3)),count)
IDL> print,points2
1 2 4 5
I supose that you want yhe same results for points and points2 :)...
Bye.
|
|
|