Re: get_unique_values: Extracting unique values in an array

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Sun Apr 13 2014 - 17:48:25 MDT

THX ...

==================

NCL has a function that generates unique random indices (subscripts).

http://www.ncl.ucar.edu/Document/Functions/Contributed/generate_unique_indices.shtml

You can see the code:

%> less $NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl

Search for 'generate_unique_indices'

On 4/13/14, 4:38 PM, Gabriel Medeiros wrote:
> Hello,
>
> I have seen a couple of threads on how to get all the unique values in an
> array, such as a discrete variable. This is a little clumsy and processor
> consuming function but works, so i thought about sharing with you. The
> attached file can be loaded or just add this to your script:
>
> ; Gabriel Abrahao - gabriel.abrahao@ufv.br
> ; Gets all the unique values that occur in var
> undef("get_unique_values")
> function get_unique_values(var)
> begin
> var1d = ndtooned(var)
> printVarSummary(var1d)
> levels = new(1,typeof(var1d))
> do i=0,dimsizes(var1d)-1
> if (ismissing(levels(0)) .eq. True) then
> if (ismissing(var1d(i)) .ne. True) then
> levels(0) = var1d(i)
> end if
> else
> if (any(levels.eq.var1d(i)) .or.
> ismissing(var1d(i)).eq.True) then
> else
> dummy = new(dimsizes(levels) + 1, typeof(levels))
> dummy(0:dimsizes(levels)-1) = levels
> dummy(dimsizes(dummy)-1) = var1d(i)
> delete(levels)
> levels = dummy
> delete(dummy)
> end if
> end if
> end do
>
> return(levels)
> end
>
> Hope it's useful, and please let me know if you can improve it,
>
> Gabriel Abrahao
> Grupo de pesquisa em Interação Atmosfera - Biosfera
> Universidade Federal de Viçosa
>
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sun Apr 13 17:48:36 2014

This archive was generated by hypermail 2.1.8 : Tue Apr 15 2014 - 10:45:19 MDT