<div dir="ltr"><div>Hi Jiali,</div><div>Note, if you have multiple years or months that have 1,1,2,2,3, etc time steps then you would need to subset for a period that does not repeat the same time numbers. After that try the following, e.g.:</div><div><br></div><div>begin<br> t1 = (/1,1,2,2,2,3,3,3,3/)<br> d1 = (/22.,12,27,11,37,18,26,24,10/)<br><br> ntim = 3<br> ndat = 4<br> missing = -999.<br> d_new = new((/ntim,ndat/),float,missing)<br> do i=0,ntim-1<br> itim = i+1<br> t_ids := ind(t1.eq.itim)<br> d2 := d1(t_ids)<br> tt = dimsizes(t_ids)<br> do j=0,ndat-1<br> if(<a href="http://j.lt.tt">j.lt.tt</a>)<br> d_new(i,j) = d2(j)<br> else<br> d_new(i,j) = missing<br> end if<br> end do<br> end do<br><br> print(d_new(0,:)+" ... "+d_new(1,:)+" ... "+d_new(2,:))<br>end</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Aug 15, 2019 at 9:23 PM Wang, Jiali via ncl-talk <<a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</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 bgcolor="white" lang="EN-US">
<div class="gmail-m_1052290060321072126WordSection1">
<p class="MsoNormal"><span style="font-size:11pt">Dear NCL team,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">I have a 1D dataset like below: you can see that I have different number of data for each time step. Now I like to convert this 1d array to a regular 2d array by assigning -999 for those grid points where
don’t have numbers.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">1d array:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">=======================<u></u><u></u></span></p>
<table class="gmail-m_1052290060321072126MsoNormalTable" style="width:130pt;border-collapse:collapse" width="173" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr style="height:16pt">
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal"><span style="color:black">time<u></u><u></u></span></p>
</td>
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal"><span style="color:black">data<u></u><u></u></span></p>
</td>
</tr>
<tr style="height:16pt">
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">1<u></u><u></u></span></p>
</td>
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">22<u></u><u></u></span></p>
</td>
</tr>
<tr style="height:16pt">
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">1<u></u><u></u></span></p>
</td>
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">12<u></u><u></u></span></p>
</td>
</tr>
<tr style="height:16pt">
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">2<u></u><u></u></span></p>
</td>
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">27<u></u><u></u></span></p>
</td>
</tr>
<tr style="height:16pt">
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">2<u></u><u></u></span></p>
</td>
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">11<u></u><u></u></span></p>
</td>
</tr>
<tr style="height:16pt">
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">2<u></u><u></u></span></p>
</td>
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">37<u></u><u></u></span></p>
</td>
</tr>
<tr style="height:16pt">
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">3<u></u><u></u></span></p>
</td>
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">18<u></u><u></u></span></p>
</td>
</tr>
<tr style="height:16pt">
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">3<u></u><u></u></span></p>
</td>
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">26<u></u><u></u></span></p>
</td>
</tr>
<tr style="height:16pt">
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">3<u></u><u></u></span></p>
</td>
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">24<u></u><u></u></span></p>
</td>
</tr>
<tr style="height:16pt">
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">3<u></u><u></u></span></p>
</td>
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">10<u></u><u></u></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span style="font-size:11pt">=======================<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">2d array: (x=4 data points for each time, y=3 time steps)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">=======================<u></u><u></u></span></p>
<table class="gmail-m_1052290060321072126MsoNormalTable" style="width:260pt;border-collapse:collapse" width="347" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr style="height:16pt">
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">22<u></u><u></u></span></p>
</td>
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">12<u></u><u></u></span></p>
</td>
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">-999<u></u><u></u></span></p>
</td>
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">-999<u></u><u></u></span></p>
</td>
</tr>
<tr style="height:16pt">
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">27<u></u><u></u></span></p>
</td>
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">11<u></u><u></u></span></p>
</td>
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">37<u></u><u></u></span></p>
</td>
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">-999<u></u><u></u></span></p>
</td>
</tr>
<tr style="height:16pt">
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">18<u></u><u></u></span></p>
</td>
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">26<u></u><u></u></span></p>
</td>
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">24<u></u><u></u></span></p>
</td>
<td style="width:65pt;padding:0in 5.4pt;height:16pt" width="87" valign="bottom" nowrap>
<p class="MsoNormal" style="text-align:right" align="right"><span style="color:black">10<u></u><u></u></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span style="font-size:11pt">=======================<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">I have been trying to use function ‘where’ but couldn’t get it working. Can you please advise?
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">ID = new ((/3, 4/), “loat”)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">do i = 0, 2 ; time step<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"> ID (i,:) = where(data(:,0) .eq. (i+1), data(:,1), -999) ;; this won’t work because the dimensions on left and right are different (4 vs 9). But if I set a j=0 to 3 for ID (i, j), then I am not sure how
to set it for data..<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">end do<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">Thank you!<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">Jiali <u></u><u></u></span></p>
</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></blockquote></div>