Re: Finding the index of the median [message #7252] |
Tue, 29 October 1996 00:00 |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Dean Schulze <schulze@cassini.lpl.arizona.edu> writes:
> David Fanning wrote:
>> Be aware that there can be multiple locations in your
>> array that are equal to the median value. The index that
>> is returned by the WHERE function will be an array of
>> all of those values.
> That is exactly why the WHERE() function won't work.
> I need to know which one of those locations is returned
> by the MEDIAN() function.
I have apparently not made myself clear. Let me try again.
Suppose this is your array of values:
array = [3, 2, 7, 8, 15, 1]
The median value is the number 7 located at the third
position in the array, i.e., at the index 2. We see this
by printing the value of the MEDIAN function.
medianValue = MEDIAN(array)
PRINT, medianValue
The number 7 is printed. What Dean wants is
the location in the array where the median value
is located.
I suggest he use the WHERE function, which returns
the index in the variable array where the medianValue
is located. Like this:
PRINT, WHERE(array EQ medianValue)
The number 2 is printed. This is the *index* into
the array where the median value (7) is located.
My point is that the median value can occur multiple
times in the array. For example:
array = [3, 2, 7, 8, 7, 15, 1]
So that what the WHERE function returns is a vector
of *all* the indices into the array where the median
value occurs. In this example, do this:
medianValue = MEDIAN(array)
PRINT, WHERE(array EQ medianValue)
The indices 2 and 4 are printed out.
This works, by the way, for multidimensional arrays.
Hope this clarifies.
David
*************************************************
* David Fanning, Ph.D.
* 2642 Bradbury Court, Fort Collins, CO 80521
* Phone: 970-221-0438 Fax: 970-221-4762
* E-Mail: davidf@dfanning.com
*
* Sometimes I go about pitying myself, and all along my
* soul is being blown by great winds across the sky.
* -- Ojibway saying
************************************************
|
|
|
Re: Finding the index of the median [message #7253 is a reply to message #7252] |
Tue, 29 October 1996 00:00  |
Dean Schulze
Messages: 9 Registered: July 1996
|
Junior Member |
|
|
Joseph M. Zawodny wrote:
>
> Dean Schulze wrote:
>>
>> David Fanning wrote:
>>
>>> Be aware that there can be multiple locations in your
>>> array that are equal to the median value. The index that
>>> is returned by the WHERE function will be an array of
>>> all of those values.
>>
>> That is exactly why the WHERE() function won't work.
>> I need to know which one of those locations is returned
>> by the MEDIAN() function.
> MEDIAN does not return an element or LOCATION, it returns a
> VALUE which may be held by one or more elements.
Sorry, careless writing on my part. I should have said
"I need to know the location of the value that is returned
by MEDIAN()".
> Let's try this again: There may be more than one value which
> equals the median value. Therefore the question you ask here
> makes no sense at all without some additional information by
> which to prioritize or otherwise sort those values which are
> equal to the median. Having said that, you should use the
> where function to find pointers to the median values and then
> perform some other task or assessment on those values.
>
> Maybe we would all understand your question better if you tell
> us which element in the following arrays is your "median element"
>
> [1,2,2,3]
>
> [1,2,2,2,3]
>
> One of the above arrays must have at least two "median elements"
> by your definition. How will you choose?
>
> Or am I just dense?
No, but a part of my original question has been left out. I
said that there are two arrays, one containing data and another
containing noise (noise is not just dependant on N in this case).
I can let MEDIAN() return any of the equivalent median values
in the data array it chooses, but I need to know the location of
the one it chooses so I can get the corresponding value out of
the noise array.
Consider a CCD with a temperature gradient that is known or
can be modeled. There may be several pixels that have the median
value from different points on the CCD, and each of those points
would have a different dark current value due to the T gradient.
In order to determine the S/N ratio of the value returned by MEDIAN()
I need to know the location of that pixel to get the right value
from a noise array (or get the right value of T from a T array).
An unusual situation, but one that MEDIAN() and WHERE() don't
seem to work with.
Dean Schulze
============================================================ ==========
"You plot the growth of the NEA [National Education Association] and
the dropping of SAT scores, and they're inversely proportional.
The problems are unions in the schools. The problem is bureaucracy.
I'm one of these people who believes the best thing we could ever do
is go to the full voucher system."
Steve Jobs
Wired Magazine, Feb. 96
http://www.hotwired.com/wired/4.02/features/jobs.html
============================================================ =========
|
|
|
Re: Finding the index of the median [message #7255 is a reply to message #7252] |
Tue, 29 October 1996 00:00  |
peter
Messages: 80 Registered: February 1994
|
Member |
|
|
Dean Schulze (schulze@cassini.lpl.arizona.edu) wrote:
: David Fanning wrote:
: > Be aware that there can be multiple locations in your
: > array that are equal to the median value. The index that
: > is returned by the WHERE function will be an array of
: > all of those values.
: That is exactly why the WHERE() function won't work.
: I need to know which one of those locations is returned
: by the MEDIAN() function.
Ooh, now I'm confused! The values are all the same, yet you wish to
distinguish which one it is you have....
|
|
|
Re: Finding the index of the median [message #7256 is a reply to message #7252] |
Tue, 29 October 1996 00:00  |
Joseph M Zawodny
Messages: 24 Registered: March 1996
|
Junior Member |
|
|
Dean Schulze wrote:
>
> David Fanning wrote:
>
>> Be aware that there can be multiple locations in your
>> array that are equal to the median value. The index that
>> is returned by the WHERE function will be an array of
>> all of those values.
>
> That is exactly why the WHERE() function won't work.
> I need to know which one of those locations is returned
> by the MEDIAN() function.
>
> Dean Schulze
>
Let's try this again: There may be more than one value which
equals the median value. Therefore the question you ask here
makes no sense at all without some additional information by
which to prioritize or otherwise sort those values which are
equal to the median. Having said that, you should use the
where function to find pointers to the median values and then
perform some other task or assessment on those values.
Maybe we would all understand your question better if you tell
us which element in the following arrays is your "median element"
[1,2,2,3]
[1,2,2,2,3]
One of the above arrays must have at least two "median elements"
by your definition. How will you choose?
Or am I just dense?
Z
--
Work: Dr. Joseph M. Zawodny Play: Joe Zawodny
NASA Langley Research Center KO4LW@amsat.org
E-mail: J.M.Zawodny@LaRC.NASA.gov zawodny@exis.net
(757) 864-2681 (757) 864-2671 FAX
|
|
|
Re: Finding the index of the median [message #7257 is a reply to message #7252] |
Tue, 29 October 1996 00:00  |
Joseph M Zawodny
Messages: 24 Registered: March 1996
|
Junior Member |
|
|
Dean Schulze wrote:
>
> David Fanning wrote:
>
>> Be aware that there can be multiple locations in your
>> array that are equal to the median value. The index that
>> is returned by the WHERE function will be an array of
>> all of those values.
>
> That is exactly why the WHERE() function won't work.
> I need to know which one of those locations is returned
> by the MEDIAN() function.
>
> Dean Schulze
>
MEDIAN does not return an element or LOCATION, it returns a
VALUE which may be held by one or more elements.
Let's try this again: There may be more than one value which
equals the median value. Therefore the question you ask here
makes no sense at all without some additional information by
which to prioritize or otherwise sort those values which are
equal to the median. Having said that, you should use the
where function to find pointers to the median values and then
perform some other task or assessment on those values.
Maybe we would all understand your question better if you tell
us which element in the following arrays is your "median element"
[1,2,2,3]
[1,2,2,2,3]
One of the above arrays must have at least two "median elements"
by your definition. How will you choose?
Or am I just dense?
Z
--
Work: Dr. Joseph M. Zawodny Play: Joe Zawodny
NASA Langley Research Center KO4LW@amsat.org
E-mail: J.M.Zawodny@LaRC.NASA.gov zawodny@exis.net
(757) 864-2681 (757) 864-2671 FAX
|
|
|
Re: Finding the index of the median [message #7258 is a reply to message #7252] |
Tue, 29 October 1996 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Dean Schulze <schulze@cassini.lpl.arizona.edu> writes:
> The median function will return the median value of an
> array. Is there anyway to obtain the index into the array
> of the median value? For example, if I find the median in an
> array of measured values how can I get the corresponding value
> from the companion noise array?
The easiest way is to use the WHERE function. Your code might
look something like this:
array = [3, 7, 2, 8, 15, 1]
noise = RANDOMU(seed, 6)
medianValue = MEDIAN(array)
index = WHERE(array EQ medianValue)
Print, noise(index)
Be aware that there can be multiple locations in your
array that are equal to the median value. The index that
is returned by the WHERE function will be an array of
all of those values.
Just a tip. The return value from the WHERE funcution
(if it finds something) is *always* an array, even if it
finds only one instance. If you are going to use that
return value as if it were a scalar value (e.g., as a counter
in a loop) be sure you subset it like this: index(0).
Yours,
David
--
David Fanning, Ph.D.
Phone: 970-221-0438
Fax: 970-221-4728
E-Mail: davidf@fortnet.org
|
|
|