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

Barry Lynn barry.h.lynn at gmail.com
Wed Nov 27 10:49:18 MST 2019

```Hi Dave:

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