[ncl-talk] Question regarding array averaging
Prashanth Bhalachandran
prashanth.bhalachandran at gmail.com
Mon Oct 16 19:44:52 MDT 2017
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 <mailto: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 <http://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/400e3150/attachment.html>
More information about the ncl-talk
mailing list