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

Home » Public Forums » archive » Re: subset a 2d array
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: subset a 2d array [message #61929] Thu, 14 August 2008 09:46
xiao zhang is currently offline  xiao zhang
Messages: 81
Registered: June 2008
Member
On Aug 14, 11:34 am, David Fanning <n...@dfanning.com> wrote:
> xiao writes:
>> Sorry David, I still got problems here. I printed out all the values
>> in the array and i found the center value which is -28.0011 but when I
>> tried to do this :
>
>> index=where(lat eq -28.0011,count)
>> xy = array_indices(lat, index[0])
>> subarray = lat[xy[0]-400:xy[0]+400, xy[1]-400:xy[1]+400]
>
>> It cannot find the index number...Why is that? Thank you?
>> PS :THIS ARRAY IS A FLOAT ARRAY.
>
> Yeah, I thought I would let you solve one problem
> at a time. :-)
>
> The "problem" is that computers cannot represent numbers
> "exactly". At least most numbers they can't. (They do
> a reasonable job with integers. :-)
>
> http://www.dfanning.com/math_tips/sky_is_falling.html
> http://www.dfanning.com/math_tips/razoredge.html
>
> Typically, if we are looking for floating values, we
> have to add/subtract a small "delta" to the number
> to be able to find it. How big should the delta be?
> Big enough to allow you to find the number you are
> looking, but not too big to add ambiguity to your
> search. You could try something like this, for example"
>
> delta = 1e-3
> index = Where(array GE (2.5-delta) AND array LE (2.5+delta), count)
>
> Or, if you are just looking for the center of the array, you
> could always do this:
>
> s = Size(array, /Dimensions)
> xcenter = s[0]/2
> ycenter = s[1]/2
> targetValue = array[xcenter, ycenter]
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming (www.dfanning.com)
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

haha, it works , thank you David~ :)
Re: subset a 2d array [message #61930 is a reply to message #61929] Thu, 14 August 2008 09:34 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
xiao writes:

> Sorry David, I still got problems here. I printed out all the values
> in the array and i found the center value which is -28.0011 but when I
> tried to do this :
>
> index=where(lat eq -28.0011,count)
> xy = array_indices(lat, index[0])
> subarray = lat[xy[0]-400:xy[0]+400, xy[1]-400:xy[1]+400]
>
>
> It cannot find the index number...Why is that? Thank you?
> PS :THIS ARRAY IS A FLOAT ARRAY.

Yeah, I thought I would let you solve one problem
at a time. :-)

The "problem" is that computers cannot represent numbers
"exactly". At least most numbers they can't. (They do
a reasonable job with integers. :-)

http://www.dfanning.com/math_tips/sky_is_falling.html
http://www.dfanning.com/math_tips/razoredge.html

Typically, if we are looking for floating values, we
have to add/subtract a small "delta" to the number
to be able to find it. How big should the delta be?
Big enough to allow you to find the number you are
looking, but not too big to add ambiguity to your
search. You could try something like this, for example"

delta = 1e-3
index = Where(array GE (2.5-delta) AND array LE (2.5+delta), count)

Or, if you are just looking for the center of the array, you
could always do this:

s = Size(array, /Dimensions)
xcenter = s[0]/2
ycenter = s[1]/2
targetValue = array[xcenter, ycenter]

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: subset a 2d array [message #61931 is a reply to message #61930] Thu, 14 August 2008 09:24 Go to previous message
xiao zhang is currently offline  xiao zhang
Messages: 81
Registered: June 2008
Member
On Aug 13, 10:53 pm, David Fanning <n...@dfanning.com> wrote:
> xiao writes:
>> hmmm... The problem is I have a array like 240*500. And all the
>> values are different. And I do not know the row and column. I only
>> know the center value should be 2.5 . Then ,how can I do that? :)
>
> index = Where(array EQ 2.5, count)
> xy = array_indices(array, index[0])
> subarray = array[xy[0]-1:xy[0]+1, xy[1]-1:xy[1]+1]
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Sorry David, I still got problems here. I printed out all the values
in the array and i found the center value which is -28.0011 but when I
tried to do this :

index=where(lat eq -28.0011,count)
xy = array_indices(lat, index[0])
subarray = lat[xy[0]-400:xy[0]+400, xy[1]-400:xy[1]+400]


It cannot find the index number...Why is that? Thank you?
PS :THIS ARRAY IS A FLOAT ARRAY.
Re: subset a 2d array [message #61932 is a reply to message #61931] Thu, 14 August 2008 07:54 Go to previous message
xiao zhang is currently offline  xiao zhang
Messages: 81
Registered: June 2008
Member
On Aug 13, 10:53 pm, David Fanning <n...@dfanning.com> wrote:
> xiao writes:
>> hmmm... The problem is I have a array like 240*500. And all the
>> values are different. And I do not know the row and column. I only
>> know the center value should be 2.5 . Then ,how can I do that? :)
>
> index = Where(array EQ 2.5, count)
> xy = array_indices(array, index[0])
> subarray = array[xy[0]-1:xy[0]+1, xy[1]-1:xy[1]+1]
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

hoho, Thank you very much~ David~
Re: subset a 2d array [message #61937 is a reply to message #61932] Wed, 13 August 2008 20:53 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
xiao writes:

> hmmm... The problem is I have a array like 240*500. And all the
> values are different. And I do not know the row and column. I only
> know the center value should be 2.5 . Then ,how can I do that? :)

index = Where(array EQ 2.5, count)
xy = array_indices(array, index[0])
subarray = array[xy[0]-1:xy[0]+1, xy[1]-1:xy[1]+1]

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: subset a 2d array [message #61938 is a reply to message #61937] Wed, 13 August 2008 20:22 Go to previous message
xiao zhang is currently offline  xiao zhang
Messages: 81
Registered: June 2008
Member
On Aug 13, 10:19 pm, David Fanning <n...@dfanning.com> wrote:
> xiao writes:
>> For example, i hava an array like this:
>
>> 13, 14, 15, 16, 17
>> 23, 24, 25,26, 27
>> 2, 4 , 5, 66 ,7
>> 13, 14, 15, 16, 17
>> 13, 14, 15, 16, 17
>
>> i know the center value is 5 .Then i want to subset the array to 3*3
>> and 5 is still the center. Just subset like this :
>
>> 24, 25,26
>> 4 , 5, 66
>> 14, 15, 16,
>
>> Any one has good ideas how can i do that?
>
> How about something like this:
>
> subarray = array[1:3, 1:3]
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
hmmm... The problem is I have a array like 240*500. And all the
values are different. And I do not know the row and column. I only
know the center value should be 2.5 . Then ,how can I do that? :)
Thank you~
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: how to preserve trailing Shallow dimensions!
Next Topic: Need help with an Iterative solution in IDL (relative newb question)

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

Current Time: Wed Oct 08 19:39:33 PDT 2025

Total time taken to generate the page: 0.00455 seconds