Re: Extracting unique values in an array (integer) ?

From: Christian Pagé <page.christian_at_nyahnyahspammersnyahnyah>
Date: Wed, 5 Mar 2008 11:43:05 +0100

Thanks Mary!

Effectively, since that function is of potential use in many other NCL
codes, I think that a built-in NCL function would be the best.

Christian

2008/3/5, Mary Haley <haley_at_ucar.edu>:
>
> Hi Christian,
>
> I didn't read your email closely enough, and you did explain what
> you meant the first time. My apologies.
>
> I don't think we have a function to do what you're asking. The
> one way I thought of is a bit kludgy:
>
> years = (/1991,1990,1991,1990,1990,1990,1991,1991/)
> qsort(years)
> ny = dimsizes(years)
> nuy = num((years(1:)-years(0:ny-2)).ne.0) + 1
> print("Number of unique years = " + nuy)
>
> This may be a function worth "officially" adding to NCL, via a built-in
> function, rather than one written in NCL.
>
>
> --Mary
>
> On Wed, 5 Mar 2008, [ISO-8859-1] Christian Pagé wrote:
>
> > Hi Mary,
> >
> > I think I didn't explain correctly what I want to achieve.
> >
> > Let a vector of time (udunits in hours since), with daily data.
> > I convert it to year, month, day, etc arrays using ut_calendar.
> > I would like to know how many years I have... but I cannot use the
> dimension
> > of years since I will have 365/366 values of each year for complete
> years,
> > and less than that for incomplete years.
> >
> > Example :
> > I have these two vectors with the same dimensions, years and months as
> > follows.
> > years = 1990 1990 1990 1990 1991 1991 1991 1991
> > month = 09 10 11 12 01 02 03 04
> >
> > I want to know how many unique years I have in the years vector, which
> would
> > be equal to 2 in that example.
> > It would be the same functionality as the sort -u | wc -l command in
> > unix.
> >
> > Many thanks
> >
> > Christian
> >
> > 2008/3/5, Mary Haley <haley_at_ucar.edu>:
> >>
> >> Hi Christian,
> >>
> >> I have a weird connection at the moment and can't get to our web
> >> pages, but I believe what you want is a function Dennis wrote called
> >> generate_unique_indices.
> >>
> >> See:
> >>
> >>
> >>
> >>
> http://www.ncl.ucar.edu/Document/Functions/Contributed/generate_unique_indices.shtml
> >>
> >>
> >> --Mary
> >>
> >>
> >>
> >>
> >> On Tue, 4 Mar 2008, [ISO-8859-1] Christian Pagé wrote:
> >>
> >>> Hi everyone,
> >>>
> >>> I searched without success...
> >>> I was wondering if there already exists a function in NCL to extract
> >> unique
> >>> values in an integer array ?
> >>>
> >>> Many thanks,
> >>>
> >>> --
> >>> Christian Pagé
> >>>
> >

-- 
Christian Pagé
http://meteocentre.com/toulouse/    http://meteoalerte.com/france/
Ingénieur d'étude en climat, CERFACS, Toulouse
Received on Wed Mar 05 2008 - 03:43:05 MST

This archive was generated by hypermail 2.2.0 : Thu Mar 13 2008 - 17:22:55 MDT