# [ncl-talk] Regression produces fatal error: regCoef_n: The input array y must have as many or more dimensions than x

Andreas Chrysanthou eeac at leeds.ac.uk
Fri Sep 1 09:30:11 MDT 2017

```Hi Adam,

You have been very helpful once more, I really appreciate your help.
The code now works like a charm and I’m not sure I should have expected the regCoef function to handle those iterations without looping over the other dimensions.

Much obliged!

Best,
Andreas

On 1 Sep 2017, at 16:01, Adam Phillips <asphilli at ucar.edu<mailto:asphilli at ucar.edu>> wrote:

Hi Andreas,
When I tested things here my returned array is all 0's with the exception of the entry at index (0,0). I am not sure why that is happening. I was able to get it to work by looping over the the lat and lon dimensions though:
finarr = acceldivf_(0,:,:)
do gg = 0,dimsizes(acceldivf_&lat)-1
do hh = 0,dimsizes(acceldivf_&lon)-1
finarr(gg,hh) = (/ regCoef(acceldivf_(:,gg,hh),mass_flux) /)
end do
end do

On Fri, Sep 1, 2017 at 8:30 AM, Andreas Chrysanthou <eeac at leeds.ac.uk<mailto:eeac at leeds.ac.uk>> wrote:

Seemingly that does it, but with a downside. The values of rc are all zeros now.

Cheers,
Andreas

On 1 Sep 2017, at 15:19, Adam Phillips <asphilli at ucar.edu<mailto:asphilli at ucar.edu>> wrote:

Hi Andreas,
In that case then I would use conform on your mass_flux array to match its' dimensions to your acceldivf_ array:
rc= regCoef_n (acceldivf_, conform(acceldivf_,mass_flux,(/0/)), 0, 0)

On Fri, Sep 1, 2017 at 8:14 AM, Andreas Chrysanthou <eeac at leeds.ac.uk<mailto:eeac at leeds.ac.uk>> wrote:

I did that beforehand just to test it and it works normally producing an array with the desired output.
But the problem is that the regression coefficients units (y/x) that I want to have as output should be when the 1D var is y and the 3D var is x.

Cheers,
Andreas

On 1 Sep 2017, at 15:03, Adam Phillips <asphilli at ucar.edu<mailto:asphilli at ucar.edu>> wrote:

Hi Andreas,
I think the error message is trying to tell you that you should switch your two input arrays. (The 2nd input array must have as many or more dimensions as the 1st one.) If switching the two arrays doesn't help let ncl-talk know..

On Fri, Sep 1, 2017 at 7:06 AM, Andreas Chrysanthou <eeac at leeds.ac.uk<mailto:eeac at leeds.ac.uk>> wrote:
Hi NCL users,

I want to calculate the regression coefficients of variable with 1 dimension (y= mass_flux)  against another which has 3 dimensions (x = acceldivf_).

Typically, according to the description of the regCoef_n (x, y, dims_x, dims_y) NCL function x and y can be arrays of any dimensionality but the dims_x and dims_x and dims_y is an integer indicating which dimension of x/y to do the calculation on, as long as it has the same number of elements.

The error I’m getting is the following: fatal:regCoef_n: The input array y must have as many or more dimensions than x

PrintVarSummary of both variables follows:

Variable: mass_flux
Type: float
Total Size: 564 bytes
141 values
Number of Dimensions: 1
Dimensions and sizes: [time | 141]
Coordinates:
time: [1960..2100]
Number Of Attributes: 1
_FillValue : 1e+20

Variable: acceldivf_
Type: float
Total Size: 839232 bytes
209808 values
Number of Dimensions: 3
Dimensions and sizes: [time | 141] x [lev | 31] x [lat | 48]
Coordinates:
time: [1960..2100]
lev: [1000.. 0.1]
lat: [-87.15909445302286..87.15909445302286]

So it fails with the above fatal error when I try:

rc= regCoef_n (acceldivf_, mass_flux, 0, 0)

Cheers,
Andreas

_______________________________________________
ncl-talk mailing list
ncl-talk at ucar.edu<mailto:ncl-talk at ucar.edu>
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk

--
Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
www.cgd.ucar.edu/staff/asphilli/<http://www.cgd.ucar.edu/staff/asphilli/>   303-497-1726<tel:(303)%20497-1726>

<http://www.cgd.ucar.edu/staff/asphilli>

_______________________________________________
ncl-talk mailing list
ncl-talk at ucar.edu<mailto:ncl-talk at ucar.edu>
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk

--
Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
www.cgd.ucar.edu/staff/asphilli/<http://www.cgd.ucar.edu/staff/asphilli/>   303-497-1726<tel:(303)%20497-1726>

<http://www.cgd.ucar.edu/staff/asphilli>

_______________________________________________
ncl-talk mailing list
ncl-talk at ucar.edu<mailto:ncl-talk at ucar.edu>
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk

--