[ncl-talk] Question regarding array averaging
Dave Allured - NOAA Affiliate
dave.allured at noaa.gov
Mon Oct 16 21:51:57 MDT 2017
Prashanth,
I do not understand how NCL could get a 3 x 3 array from a 9 x 11
construction like that. However, here is a complete smaller example of
what I think you described, a weighted average on one dimension. a1...a4
are simple 1-D arrays of length 5. Does this do what you want?
ncl 37> b = (/ a1, a2, a3, a4 /)
ncl 38> printVarSummary (b)
Type: integer
Dimensions and sizes: [4] x [5]
ncl 39> print (w)
Type: float
Dimensions and sizes: [4]
(0) 0.2
(1) 0.3
(2) 0.3
(3) 0.2
ncl 40> wsum = dim_avg_wgt_n (b, w, 0, 0)
ncl 41> print (wsum)
Type: float
Dimensions and sizes: [5]
(0) 1.6
(1) 3.2
(2) 4.8
(3) 6.4
(4) 8
--Dave
On Mon, Oct 16, 2017 at 7:44 PM, Prashanth Bhalachandran <
prashanth.bhalachandran at gmail.com> wrote:
> Hi Dave,
> I tried this too initially. But it is giving erroneous results in terms of
> dimensionality.
>
> If the initial arrays are : [lev_ | 11]
> Then : arr = avg((/a1,a2,a3,a4,a5,a6,a7,a8,a9/))
> printVarSummary(arr)
>
> Variable: arr
> Type: float
> Total Size: 36 bytes
> 9 values
> Number of Dimensions: 2
> Dimensions and sizes: [3] x [3]
> Coordinates:
> Number Of Attributes: 1
> _FillValue : 1e+30
>
> My intent is that I take these 9 [11 dimensioned] vectors and apply a
> weighted average.
> weights = (/0.0625,0.0625,0.0625,0.0625,0.5,0.0625,0.0625,0.0625,0.0625/)
>
> For example, if these a1..a9 were single values, I would do something like
> arr = (/ (/a1,a2,a3/), (/a4,a5,a6/), (/a7,a8,a9/)/)
> weights = (/ (/0.0625,0.0625,0.0625/), (/0.0625,0.5,0.0625/),
> (/0.0625,0.0625,0.0625/)/)
> output = dim_avg_wgt(ndtooned(arr),ndtooned(weights),1)
>
> (I know I can avoid the ndtooned, but that’s besides the point). I am
> finding it hard to translate this procedure when a1 … a9 are vectors of 11
> values each instead of one.
>
>
>
> On Oct 16, 2017, at 6:10 PM, Dave Allured - NOAA Affiliate <
> dave.allured at noaa.gov> wrote:
>
> Prashanth,
>
> All of the original arrays have exactly the same dimensions. This means
> you can easily combine them into a single 2-D virtual array, using array
> constructors (/ ... /). See the NCL user manual for details. See if this
> works.
>
> result = avg ( (/ a1, a2, a3, a4, a5, a6, a7, a8, a9 /) )
>
> --Dave
>
>
> On Mon, Oct 16, 2017 at 6:05 PM, Prashanth Bhalachandran <
> prashanth.bhalachandran at gmail.com> wrote:
>
>> Hello all,
>> I am trying to take an average of nine 1D arrays that I have .. a1 to a9
>> all of them of the dimension [lev | 11]
>>
>> If my understanding is right, the average functions in NCL doesn’t simply
>> allow you to do avg(a1….a9). Please correct me if I am wrong.
>>
>> The other way around is that I combine the 9 arrays in to a 11x9 array
>> using a function that Dennis have posted out in the past. Is this the way
>> around it? Or is there a simpler/less computationally intensive way of
>> doing it?
>>
>> function combine (x[*], y[*])
>> begin
>> nx = dimsizes(x)
>> ny = dimsizes(y)
>> if (nx.eq.my) then
>> xy = new ( (/nx,2/), typeof(x)) ; (row,col)
>> xy(:,0) = (/ x /)
>> xy(:,1) = (/ y /)
>> return (xy)
>> end if
>>
>> print("combine error")
>> exit
>> end
>>
>> Thank you,
>> Prashanth
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171016/2730905a/attachment-0001.html>
More information about the ncl-talk
mailing list