<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Hi Anne,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">The short answer is that</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"> t2m_test2(4,0,0) and t2m_reshape(4,0,0,0) </div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">are not the same element. What are the same elements are:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">t2m_test2(40,0,0) and t2m_reshape(4,0,0,0)<br></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">The simpler way to think about it is to ignore the rightmost two dimensions of both arrays, since they are the same, and instead focus on the leftmost dimension of t2m_test2 and the leftmost two dimensions of t2m_reshape.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Here's a column of the leftmost index of t2m_test2, and how it maps into the leftmost 2 indexes of t2m_reshape:</div><div class="gmail_default" style="font-size:small"><font face="monospace, monospace"> </font></div><div class="gmail_default"><font face="monospace, monospace"><div class="gmail_default"> t2m_test2 t2m_reshape</div><div class="gmail_default"> ( 0) --> (0,0)</div><div class="gmail_default"> ( 1) --> (0,1)</div><div class="gmail_default"> . . .</div><div class="gmail_default"> ( 9) --> (0,9)</div><div class="gmail_default"> (10) --> (1,0) ; Note the shift here</div><div class="gmail_default"> (11) --> (1,1)</div><div class="gmail_default"> (12) --> (1,2)</div><div class="gmail_default"> . . .</div><div class="gmail_default"> (20) --> (2,0) ; Note the shift here</div><div class="gmail_default"> (21) --> (2,1)</div><div class="gmail_default"><div class="gmail_default"> . . .</div></div><div class="gmail_default"> (39) --> (3,9)</div><div class="gmail_default"> (40) --> (4,0) ; Again, the shift</div><div class="gmail_default"> . . .</div></font><br>Here's how to look at it if you fill in some dimensions on the right:</div><div class="gmail_default"><br><font face="monospace, monospace"><div class="gmail_default"> t2m_test2 t2m_reshape</div><div class="gmail_default"> ( 0,0,0) --> (0,0,0,0)</div><div class="gmail_default"> ( 1,0,0) --> (0,1,0,0)</div><div class="gmail_default"> . . .</div><div class="gmail_default"> ( 9,0,0) --> (0,9,0,0)</div><div class="gmail_default"> (10,0,0) --> (1,0,0,0)</div><div class="gmail_default"> (11,0,0) --> (1,1,0,0)</div><div class="gmail_default"> (12,0,0) --> (1,2,0,0)</div><div class="gmail_default"> . . .</div><div class="gmail_default"> (20,0,0) --> (2,0,0,0)</div><div class="gmail_default"> (21,0,0) --> (2,1,0,0)</div><div class="gmail_default"><div class="gmail_default"> . . .</div></div><div class="gmail_default"> (39,0,0) --> (3,9,0,0)</div></font><div class="gmail_default" style="font-family:monospace,monospace"> (40,0,0) --> (4,0,0,0)</div><font face="monospace, monospace"><div class="gmail_default"> . . .</div></font><br>You can verify this with a simple program:</div><div class="gmail_default"><br><div><font face="monospace, monospace"><div>dims_3d = (/60,18,360/)</div><div>dims_4d = (/6,10,18,360/)</div><div><br></div><div>t2m_test2 = random_uniform(0.,10.,dims_3d)</div><div>t2m_reshape = reshape(t2m_test2,dims_4d)</div><div><br></div><div>print("t2m_test2d (3d) t2m_reshape (4d)")</div><div>print("( 0,0,0) " + t2m_test2( 0,0,0) + " --> (0,0,0,0) " + t2m_reshape(0,0,0,0))</div><div>print("( 1,0,0) " + t2m_test2( 1,0,0) + " --> (0,1,0,0) " + t2m_reshape(0,1,0,0))</div><div>print("( 4,0,0) " + t2m_test2( 4,0,0) + " --> (0,4,0,0) " + t2m_reshape(0,4,0,0))<br>print("( 9,0,0) " + t2m_test2( 9,0,0) + " --> (0,9,0,0) " + t2m_reshape(0,9,0,0))<br></div><div>print("(10,0,0) " + t2m_test2(10,0,0) + " --> (1,0,0,0) " + t2m_reshape(1,0,0,0))</div><div>print("(11,0,0) " + t2m_test2(11,0,0) + " --> (1,1,0,0) " + t2m_reshape(1,1,0,0))</div><div>print("(12,0,0) " + t2m_test2(12,0,0) + " --> (1,2,0,0) " + t2m_reshape(1,2,0,0))</div><div>print("(20,0,0) " + t2m_test2(20,0,0) + " --> (2,0,0,0) " + t2m_reshape(2,0,0,0))</div><div>print("(21,0,0) " + t2m_test2(21,0,0) + " --> (2,1,0,0) " + t2m_reshape(2,1,0,0))</div><div>print("(39,0,0) " + t2m_test2(39,0,0) + " --> (3,9,0,0) " + t2m_reshape(3,9,0,0))</div><div>print("(40,0,0) " + t2m_test2(40,0,0) + " --> (4,0,0,0) " + t2m_reshape(4,0,0,0))</div></font><br><br>Output:</div><font face="monospace, monospace"><div style="font-size:small"><br></div><div style=""><div style="font-size:small">( 0,0,0) 3.23711 --> (0,0,0,0) 3.23711</div><div style="">( 1,0,0) 1.44937 --> (0,1,0,0) 1.44937</div>
<div style=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">( 4,0,0)</span><span class="gmail-Apple-converted-space" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">1.50282 </span><span class="gmail-Apple-converted-space" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">--> (0,4,0,0) 1.50282</span></div><div style="">( 9,0,0) 1.38478 --> (0,9,0,0) 1.38478<br></div><div style="">(10,0,0) 5.53886 --> (1,0,0,0) 5.53886</div><div style="font-size:small">(11,0,0) 4.32108 --> (1,1,0,0) 4.32108</div><div style="font-size:small">(12,0,0) 3.80684 --> (1,2,0,0) 3.80684</div><div style="font-size:small">(20,0,0) 3.36136 --> (2,0,0,0) 3.36136</div><div style="font-size:small">(21,0,0) 4.84756 --> (2,1,0,0) 4.84756</div><div style="font-size:small">(39,0,0) 1.74234 --> (3,9,0,0) 1.74234</div><div style="font-size:small">(40,0,0) 1.17584 --> (4,0,0,0) 1.17584</div></div></font></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Hope this helps!</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">--Mary</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><br></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jan 24, 2019 at 5:57 AM Anne <<a href="mailto:anne.seidenglanz@unive.it">anne.seidenglanz@unive.it</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Hello everyone,<div><br></div><div>I am trying to use 'reshape' to convert a 60 x 180 x 360 matrix to a 6 x 10 x 18 x 360 matrix in the following way:</div><div><br></div><div><div> </div><div> dir_s ="/work/as10017/CESM/archive/Ensemble_means/yearly_means_h0/1993/"</div><div> fil_s = systemfunc("ls "+dir_s+"/sps_199311_*_<a href="http://icef.cam.h0.6mth_grid.surface.nc" target="_blank">icef.cam.h0.6mth_grid.surface.nc</a>")</div><div> f_s = addfiles(fil_s,"r")</div><div> t2m_test2 = f_s[:]->TREFHT</div><div><br></div><div> printVarSummary(t2m_test2)</div><div> t2m_reshape = reshape(t2m_test2,(/6,10,180,360/))</div><div> copy_VarCoords(t2m_test2(0,:,:), t2m_reshape(0,0,:,:))</div><div> printVarSummary(t2m_reshape)</div><div><br></div></div><div><br></div><div>I am getting the 1st dimension of my 60 x 180 x 360 array by using a wildcard (*) and 'systemfunc' so that it concatenates (in a folder) 10 files with each 6 x 180 x 360 dimensions (months x mlat x nlon). I then reshaped the 60 x 180 x 360 array so as to reflect the original file structure : 6 x 10 x 180 x 360 (months x member x mlat x nlon).</div><div><br></div><div>This worked fine, however, if I check with </div><div><br></div><div><div> print(t2m_test2(4,0,0))</div><div> print(t2m_reshape(4,0,0,0))</div></div><div><br></div><div>I do not get the same values (223 Kelvin vs. 221 Kelvin). Did I miss something here?</div><div><br></div><div><br></div><div>thanks</div><div>Anne</div></div></div>
_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
</blockquote></div>