Re: Problems with num function

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Wed, 13 May 2009 08:54:30 -0600 (MDT)

Katie,

I should have mentioned that the other way to do what you want is to
remove the "ind" part:

  print(num(month.eq.1))

--Mary

On Wed, 13 May 2009, Mary Haley wrote:

> Hi Katie,
>
> The "num" function doesn't count the number of values in an array. It
> counts the locations in an array where the values evaluate to "True".
>
> One of the values in your array is equal to 0, which evaluates to
> False. So, even though you have 20 values, only 19 of them are
> "True", and hence "num" returns 19.
>
> I think you want to use "dimsizes" instead of "num".
>
> --Mary
>
>
> On Tue, 12 May 2009, Katie Holman wrote:
>
>> Hi All,
>>
>> I would like to bring attention to a simple problem I am encountering
>> with the num function. I have a script written that is summing up the
>> number of individual months in my data file. The total number of time
>> elements is 240 - so there are 20 Jan., 20 Feb., etc.
>>
>> The command below produces a list of twenty values.
>>
>> print(ind(month.eq.1))
>>
>> (0) 0
>> (1) 12
>> (2) 24
>> (3) 36
>> (4) 48
>> (5) 60
>> (6) 72
>> (7) 84
>> (8) 96
>> (9) 108
>> (10) 120
>> (11) 132
>> (12) 144
>> (13) 156
>> (14) 168
>> (15) 180
>> (16) 192
>> (17) 204
>> (18) 216
>> (19) 228
>>
>> When I count the number of times a month number of 1 occurs, the
>> function num only catches 19 of them. The command line is below.
>>
>> print(num(ind(month.eq.1)))
>>
>> (0) 19
>>
>> I have gotten around the problem by instead using dimsizes, but I
>> thought everyone should be aware of the issue.
>>
>> Thank you,
>>
>> Katie Holman
>> UW-Madison
>> _______________________________________________
>> 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
>
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed May 13 2009 - 08:54:30 MDT

This archive was generated by hypermail 2.2.0 : Tue May 19 2009 - 09:17:29 MDT