<div dir="ltr">Jatin,<div><br></div><div>In NCL, you can do this with only one loop over your two-column list of point indices.  I think this is reasonably obvious and efficient.  Here is a compact example to match your example, untested:</div><div><br></div><div>    pre-define hfx2 as (103,2)<br></div><div><div>    hfx2(:,0) = hfx(:,1,2)<br></div><div></div></div><div><div class="gmail_extra"><div>    hfx2(:,1) = hfx(:,2,4)</div><div><br></div><div>NCL also provides coordinate subscripting, which may add some value when picking out grid points like this.  Then you don't need to separately convert coordinates to indices.  Note the curly brackets:</div><div><br></div><div>    hfx2(:,0) = hfx(: , {lats(0)} , {lons(0)} )</div><div>    etc.</div><div><br></div><div>My editorial opinion is that is a rather fancy multidimensional indexing scheme that python provides, perhaps not altogether intuitive.  Well, um, NCL's curly brackets are also a bit unusual, but you get used to them.</div><div><br></div><div>--Dave</div><div><br></div><div><br></div><div></div><div class="gmail_quote">On Tue, Nov 28, 2017 at 7:59 PM, Jatin Kala <span dir="ltr"><<a href="mailto:jatin.kala.jk@gmail.com" target="_blank">jatin.kala.jk@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
Suppose we have a 3-D array, size (103,lat,lon), or whatever...<br>
<br>
If i want to extract a time series at two points, say (:,1,2) and (:,2,4), then in Python you can do it quite simply, and you end up with an array which is size (103,2), which one would expect:<br>
<br>
import netCDF4 as nc<br>
f = nc.Dataset('wrfout_d03_cntl')<br>
hfx = f.variables['HFX'][:]<br>
hfx2 = hfx[:,[1,2],[2,4]]<br>
print(hfx2.shape)<br>
<br>
But if i do the same thing in ncl, i actually get an array (103,2,2), which is not what one would expect:<br>
<br>
f = addfile("wrfout_d03_cntl","r")<br>
hfx = f->HFX<br>
hfx2 = hfx(:,(/1,2/),(/2,4/))<br>
print(dimsizes(hfx2))<br>
<br>
The only way to get the right answer in ncl, is to pre-define hfx as (103,2), then loop through the indices, and put in the array within the loop.<br>
<br>
Does anyone else find this rather counter-intuitive? I.e., the way ncl does array indexing in such cases? Is there a way to achieve the same result in ncl without having to loop?<br>
<br>
Cheers,<br>
<br>
Jatin<br></blockquote></div></div></div></div>