Re: Difficulty with N_ELEMENTS command [message #79222] |
Sun, 12 February 2012 11:21 |
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  |
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  |
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
|
|
|
|
|