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

Home » Public Forums » archive » Re: Difficulty with N_ELEMENTS command
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: Difficulty with N_ELEMENTS command [message #79222] Sun, 12 February 2012 11:21
Yngvar Larsen is currently offline  Yngvar Larsen
Messages: 134
Registered: January 2010
Senior Member
On Feb 12, 8:14 pm, Yngvar Larsen <larsen.yng...@gmail.com> wrote:

> A one-liner soulution (mostly because it fun :) could be
>
> exceed_freq = total(precip_day gt
> transpose(smoothed[*,lindgen(nyears)]), 2)
>
> or
>
> exceed_freq = total(transpose(precip_day) gt
> smoothed[*,lindgen(nyears)], 1)
>
> --
> Yngvar

Ironically, Google Groups decided that my one-liners really should be
two-liners :)

--
Yngvar
Re: Difficulty with N_ELEMENTS command [message #79224 is a reply to message #79222] Sun, 12 February 2012 11:14 Go to previous message
Yngvar Larsen is currently offline  Yngvar Larsen
Messages: 134
Registered: January 2010
Senior Member
On Feb 10, 5:03 am, Andrew King <andrewkin...@gmail.com> wrote:
> Hi.
>
> I'm trying to create an array of the number of elements that satisfy a
> certain criterion as below.
>
> FOR m=0,nyears-1 DO BEGIN
>       exceed_freq(m)=N_ELEMENTS(WHERE(precip_day(m,*) gt smoothed(*)))
> ENDFOR
>
> The problem I have is that for some years in my program there are no
> elements that satisfy this criterion, however the value returned in
> the array 'exceed_freq' is 1 instead of 0.
>
> I would appreciate any comments.

A one-liner soulution (mostly because it fun :) could be

exceed_freq = total(precip_day gt
transpose(smoothed[*,lindgen(nyears)]), 2)

or

exceed_freq = total(transpose(precip_day) gt
smoothed[*,lindgen(nyears)], 1)

--
Yngvar
Re: Difficulty with N_ELEMENTS command [message #79233 is a reply to message #79224] Thu, 09 February 2012 20:32 Go to previous message
Andrew King is currently offline  Andrew King
Messages: 2
Registered: February 2012
Junior Member
On Feb 10, 3:28 pm, Gianguido Cianci <gianguido.cia...@gmail.com>
wrote:
> You could also try "the IDL" way:
>
> s=size(precip_day, /dim)
> smoothed2=rebin(smoothed, s, /sample)
>
> test=precip_day gt smoothed2
> exceed_freq=total(test, 1)
>
> Look mum! No loops!!
>
> G

Works perfectly now. Thanks very much.

Andrew
Re: Difficulty with N_ELEMENTS command [message #79236 is a reply to message #79233] Thu, 09 February 2012 20:28 Go to previous message
cgguido is currently offline  cgguido
Messages: 195
Registered: August 2005
Senior Member
You could also try "the IDL" way:


s=size(precip_day, /dim)
smoothed2=rebin(smoothed, s, /sample)

test=precip_day gt smoothed2
exceed_freq=total(test, 1)

Look mum! No loops!!


G
Re: Difficulty with N_ELEMENTS command [message #79237 is a reply to message #79236] Thu, 09 February 2012 20:21 Go to previous message
cgguido is currently offline  cgguido
Messages: 195
Registered: August 2005
Senior Member
Try:

FOR m=0,nyears-1 DO BEGIN
dummy=WHERE(precip_day[m,*] gt smoothed, n)
exceed_freq[m]=n
ENDFOR


Hope it helps.

G
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: confidence level
Next Topic: Re: Writing 6sv (radiative transfer model) input files or reading output files

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

Current Time: Wed Oct 08 13:52:55 PDT 2025

Total time taken to generate the page: 0.00595 seconds