[ncl-talk] Wondering why I am getting this dimensions error

Barry Lynn barry.h.lynn at gmail.com
Wed Nov 27 12:20:04 MST 2019


Hi:

Normally, it would be a sum of 2s and 1s, but because I am only doing the
sum once (for each k), it should becomes an array of  just 0's and  1s.

Originally, I thought if I set a 1 D array equal to the where statement, it
would sum the 2d array.  To do that, I had to actually sum it (add_q).

Barry

On Wed, Nov 27, 2019 at 8:58 PM Rashed Mahmood <rashidcomsis at gmail.com>
wrote:

> Sorry for chipping in here, and may be I am wrong but I do not follow the
> logic:
>
> If you do: sum_q :=  where(qs(k,:,:).ge.0.1,sum_q+1,sum_q)
>
> The variable "sum_q" would be a 2d array containing *2s* and *1s*. Do you
> want a sum of 2s and 1s or you want a sum of qs(k,:,:) where it is greater
> than 0.1?
>
>
>
>
>
>
>
> On Wed, Nov 27, 2019 at 10:50 AM Barry Lynn via ncl-talk <
> ncl-talk at ucar.edu> wrote:
>
>> Hi:
>>
>> The problem with the previous suggestion was that the sum_q became a 2
>> dimensional variable..  I needed it to be a 1D variables. I found this out
>> by using the "function" printVarSummary
>>
>> Here is the correct solution for my needs, based on the very helpful
>> comments up to now.
>>
>> Thanks
>>
>> (sum_q was defined as a 2d variable -- note: sum_q is not really a sum,
>> as used here, but defined as 1 whereever qs > 0.1).
>>
>>        sum_q = 0
>>
>>        sum_q(0,0) = 1 ; just so I don't divide by 0!
>>
>>        sum_q =  where(qs(k,:,:).ge.0.1,sum_q+1,sum_q)
>>
>>        add_q = sum(sum_q); a 1d variable
>>
>>  ;      printVarSummary(qs_1(k))
>>
>>   ;     printVarSummary(sum_q)
>>
>>   ;     printVarSummary(add_q)
>>
>>        qs_1(k)  = sum(qs(k,:,:))/add_q+qs_1(k)
>>
>> On Wed, Nov 27, 2019 at 8:18 PM Dennis Shea <shea at ucar.edu> wrote:
>>
>>> re:   :=
>>> Yes.
>>>
>>> On Wed, Nov 27, 2019 at 10:49 AM Barry Lynn via ncl-talk <
>>> ncl-talk at ucar.edu> wrote:
>>>
>>>> Hi Dave:
>>>>
>>>> Thank you for your suggestions.
>>>>
>>>> I actually need to sum_q for all elements of the remaining (:,:) 2d
>>>> array to obtain a single number.
>>>>
>>>> I am dividing one number by it.
>>>>
>>>> I assume that it is okay to put the := and that I will get the sum over
>>>> all 2d elements?
>>>>
>>>> On Wed, Nov 27, 2019 at 7:40 PM Dave Allured - NOAA Affiliate <
>>>> dave.allured at noaa.gov> wrote:
>>>>
>>>>> "sum_q = 1." defines this variable as scalar.  Then the where
>>>>> statement attempts to write a 2-D array onto a scalar.  The assignment
>>>>> statement is not allowed to change dimensions.
>>>>>
>>>>> One way to fix this would be to use the reassignment operator ":=",
>>>>> which IS allowed to change dimensions on assignment.
>>>>>
>>>>> Another way to fix this would be to define sum_q as a 2-D array before
>>>>> the start of the loop.  I suspect that is what you really intended.
>>>>>
>>>>>
>>>>> On Wed, Nov 27, 2019 at 10:22 AM Barry Lynn via ncl-talk <
>>>>> ncl-talk at ucar.edu> wrote:
>>>>>
>>>>>> Hi:
>>>>>>
>>>>>> I have some simple code.
>>>>>>
>>>>>>       do k = 0,dims3d(0)-1
>>>>>>
>>>>>>        qs(k,:,:) = where(qs(k,:,:).lt.0.1,q_null(k,:,:),qs(k,:,:))
>>>>>>
>>>>>>        sum_q = 1.
>>>>>>
>>>>>>        sum_q =  where(qs(k,:,:).ge.0.1,sum_q+1,sum_q)
>>>>>>
>>>>>>        qs_1(k) = sum(qs(k,:,:))/sum_q+qs_1(k)
>>>>>>
>>>>>>       end do
>>>>>>
>>>>>>
>>>>>> Why can't I do the "where" sum?
>>>>>>
>>>>>>
>>>>>> fatal:Number of dimensions on right hand side do not match number of
>>>>>> dimension in left hand side
>>>>>>
>>>>>> --
>>>>>> Barry H. Lynn, Ph.D
>>>>>> Senior Associate Scientist, Lecturer,
>>>>>> The Institute of the Earth Science,
>>>>>> The Hebrew University of Jerusalem,
>>>>>> Givat Ram, Jerusalem 91904, Israel
>>>>>> Tel: 972 547 231 170
>>>>>> Fax: (972)-25662581
>>>>>>
>>>>>> C.E.O, Weather It Is, LTD
>>>>>> Weather and Climate Focus
>>>>>> http://weather-it-is.com
>>>>>> Jerusalem, Israel
>>>>>> Local: 02 930 9525
>>>>>> Cell: 054 7 231 170
>>>>>> Int-IS: x972 2 930 9525
>>>>>>
>>>>>
>>>>
>>>> --
>>>> Barry H. Lynn, Ph.D
>>>> Senior Associate Scientist, Lecturer,
>>>> The Institute of the Earth Science,
>>>> The Hebrew University of Jerusalem,
>>>> Givat Ram, Jerusalem 91904, Israel
>>>> Tel: 972 547 231 170
>>>> Fax: (972)-25662581
>>>>
>>>> C.E.O, Weather It Is, LTD
>>>> Weather and Climate Focus
>>>> http://weather-it-is.com
>>>> Jerusalem, Israel
>>>> Local: 02 930 9525
>>>> Cell: 054 7 231 170
>>>> Int-IS: x972 2 930 9525
>>>>
>>>> _______________________________________________
>>>> ncl-talk mailing list
>>>> ncl-talk at ucar.edu
>>>> List instructions, subscriber options, unsubscribe:
>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>
>> --
>> Barry H. Lynn, Ph.D
>> Senior Associate Scientist, Lecturer,
>> The Institute of the Earth Science,
>> The Hebrew University of Jerusalem,
>> Givat Ram, Jerusalem 91904, Israel
>> Tel: 972 547 231 170
>> Fax: (972)-25662581
>>
>> C.E.O, Weather It Is, LTD
>> Weather and Climate Focus
>> http://weather-it-is.com
>> Jerusalem, Israel
>> Local: 02 930 9525
>> Cell: 054 7 231 170
>> Int-IS: x972 2 930 9525
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>

-- 
Barry H. Lynn, Ph.D
Senior Associate Scientist, Lecturer,
The Institute of the Earth Science,
The Hebrew University of Jerusalem,
Givat Ram, Jerusalem 91904, Israel
Tel: 972 547 231 170
Fax: (972)-25662581

C.E.O, Weather It Is, LTD
Weather and Climate Focus
http://weather-it-is.com
Jerusalem, Israel
Local: 02 930 9525
Cell: 054 7 231 170
Int-IS: x972 2 930 9525
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20191127/27ddc06c/attachment.html>


More information about the ncl-talk mailing list