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

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

```Hi Rashed:

I thought that you should be correct as well.  However, when I printed out
sum_q, NCL said that it was a 2 dimensional variable!  I was quite
surprised to see this.

So, sum_q is changed from a 1 dimensional variable to a 2 dimensional
variables (rather than the other way around, where the 1 dimensional
variable forces the where statement operating on 2 dimensions to become a 1
dimensional statement.

sum_q = 0.

;      sum_q(0,0) = 1

sum_q :=  where(qs(k,:,:).ge.0.1,sum_q+1,sum_q)

Variable: sum_q

Type: float

Total Size: 357604 bytes

89401 values

Number of Dimensions: 2

Dimensions and sizes: [299] x [299]

Coordinates:

Number Of Attributes: 1

_FillValue : 9.96921e+36

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20191128/c2ef8149/attachment.html>
```