Hi Arnold ..
Both question require the user to conform the arrays.
Untested
[1]
--- undef ("resid_arnold_3d") function resid_arnold_3d (x[*][*][*]:numeric, y[*][*][*] \ ,rc[*][*]:numeric ) ; residual for x[*], y[*], rc, xave, yave ; res = y - (rc*(x-xave) + yave) ; Usage:rc = regCoef(x,y) res = resid_arnold_3d(x, y, rc) begin xave2d = dim_avg_n(x, 0) ; xave(nlat,mlon) yave2d = dim_avg_n(y, 0) : yave(nlat,mlon) xave3d = conform( x, xave_2d, (/1,2/)) yave3d = conform( y, yave_2d, (/1,2/)) rc3d = conform( x, rc , (/1,2/)) resid3d = y - (rc3d*(x-xave3d)+yave3d) resid3d@long_name = "residual" copy_VarCoords(x, resid3d) return(resid3d) end ++++++++++++++ [2] If say b(time), a(lat,lon) undef("mult_arnold") function mult_arnold(a[*][*]:numeric, b[*]:numeric) begin nb = dimsizes(b) ; nb[1] na = dimsizes(a) ; na(2) A = conform_dims( (/nb, na(0), na(1)/), a, (/1,2/) ) B = conform_dims( (/nb, na(0), na(1)/), b, (/ 0 /) ) ab = A*B ; element-by-element ab!0 = b!0 ; copy named dimension ab&time = b&time ; assign values to named dimension ab!1 = a!0 ab!2 = a!1 ab&lat = a&lat ab&lon = a*lon return(ab) end undef("arnold") ; ncl-talk: ; to calculate residual. > > However, it seems only can work with 1d array, how can we calculate with > 2d or 3d array. > > Also > > Say: > > A = [lat] [lon] ;; say it’s slope > > B= [time] ;; say it’s a nino3.4 index > > How can we calculate: > > C = A*B > > Or > > C = A#B function arnold ( A[*]:numeric, B[*][*]:numeric) begin na= dimsizes(A) nlat = dimsizes(lat) mlon = dimsizes(lon) AT = con On 4/12/12 6:15 PM, Arnold.Sullivan@csiro.au wrote: > Hi guys, > > I saw the one from Dennis’ reply on 29 Feb regarding to calculate residual. > > However, it seems only can work with 1d array, how can we calculate with > 2d or 3d array. > > Also > > Say: > > A = [lat] [lon] ;; say it’s slope > > B= [time] ;; say it’s a nino3.4 index > > How can we calculate: > > C = A*B > > Or > > C = A#B > > Cheers, > > Arnold > > > > _______________________________________________ > ncl-talk mailing list > List instructions, subscriber options, unsubscribe: > http://mailman.ucar.edu/mailman/listinfo/ncl-talk _______________________________________________ ncl-talk mailing list List instructions, subscriber options, unsubscribe: http://mailman.ucar.edu/mailman/listinfo/ncl-talkReceived on Mon Apr 16 10:54:51 2012
This archive was generated by hypermail 2.1.8 : Fri Apr 20 2012 - 16:21:18 MDT