[ncl-talk] Using NCL function get_unique_values, but maintain original array order

Hoffman Cheung hoffmancheung at gmail.com
Sat May 27 06:05:28 MDT 2017


Hi Mary,

If one wants to get the indices of an unsorted array after sorting by
qsort, one can manually assign a unique index for the array before
reordering.

For example,

a = (/6,8,10,2,4/)
a!0 = "index"
a&index = (/0,1,2,3,4/)

qsort(a)

print(a + " " + a&index)

The result is:
2 3
4 4
6 0
8 1
10 2

Is it possible to modify the function get_unique_index in such a way that
it can also return the associated coordinate variable?
If it is possible, this would be easy to get the index of the unsorted
array (for 1-D and multiple-dimensional array).

Best Regards,
Hoffman




2017-05-26 18:18 GMT+02:00 Mary Haley <haley at ucar.edu>:

> Hi Alan,
>
> That's a good question, and I'm afraid we don't have a function to do
> that. The problem is that the function has to sort the values in order to
> effectively find the unique elements, and it doesn't bother unsorting them
> when done. This would add a potentially expensive extra step that people
> may not want. However, I do see the value of not sorting the values.
>
> I've attached a function that unsorts the values after you call
> get_unique_values. If you have a lot of values, this may add noticeable
> time to execute. Also, this will currently only work on a 1D array.
>
> I created a ticket for this, in case we get more requests for this and
> need to create a more elegant solution (NCL-2618).
>
> --Mary
>
>
>
>
> On Thu, May 25, 2017 at 11:33 AM, Alan Rhoades <alan.m.rhoades at gmail.com>
> wrote:
>
>> Hello,
>>
>> I'm currently using this nifty NCL function get_unique_values to sort
>> through an array and extract unique strings and/or floats from in-situ
>> station data.
>>
>> My problem is that the extracted values are then sorted alphabetically
>> and/or lowest to highest.
>>
>> Is it possible to use this function (or a similar) and maintain the
>> ordering from the original array which the strings/floats were extracted
>> from?
>>
>> Best,
>>
>> AR
>>
>> --
>>
>> *Alan Rhoades, Ph.D. | Lawrence Berkeley National Laboratories*
>> *Hydroclimate Uncertainty Postdoctoral Fellow | Project Hyperion
>> <http://climate.ucdavis.edu/hyperion/>*
>> *arhoades at lbl.gov <arhoades at lbl.gov> | alan.m.rhoades at gmail.com
>> <alan.m.rhoades at gmail.com>*
>> *Website <http://alanrhoades.weebly.com/> | Research Gate
>> <https://www.researchgate.net/profile/Alan_Rhoades> **| **Google Scholar
>> <https://scholar.google.gr/citations?user=AVFLiFsAAAAJ&hl=en> **| LinkedIn
>> <https://www.linkedin.com/pub/alan-rhoades/22/5bb/52a>*
>> * <https://scholar.google.gr/citations?user=AVFLiFsAAAAJ&hl=en>*
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170527/3a926d21/attachment.html 


More information about the ncl-talk mailing list