<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" id="owaParaStyle"></style>
</head>
<body fpstyle="1" ocsi="0">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Thanks, Dave and Kyle. Both your replies were extremely helpful and I have something working now.&nbsp;
<div>Matt</div>
<div><br>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div id="divRpF360244" style="direction: ltr;"><font face="Tahoma" size="2" color="#000000"><b>From:</b> Dave Allured - NOAA Affiliate [dave.allured@noaa.gov]<br>
<b>Sent:</b> Wednesday, September 09, 2015 10:28 PM<br>
<b>To:</b> Kyle Griffin<br>
<b>Cc:</b> Matthew Fearon; ncl-talk@ucar.edu<br>
<b>Subject:</b> Re: [ncl-talk] max index on a single dimension for a multidimensional array without loop<br>
</font><br>
</div>
<div></div>
<div>
<div dir="ltr">Kyle, I agree.&nbsp; But I think Matt wants a grid of time indices, not just the maximum values.&nbsp; Use dim_max_n to begin, then more work to get the indices.
<div><br>
</div>
<div>
<div>&nbsp; dims_3d = dimsizes (data) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; (time,lat,lon)</div>
<div>&nbsp; ntimes &nbsp;= dims_3d(0)</div>
<div>&nbsp; max_2d &nbsp;= dim_max_n (data, 0) &nbsp; ; grid of max point values (lat,lon)</div>
<div>&nbsp; max_3d &nbsp;= conform_dims (dims_3d, max_2d, (/1,2/)) &nbsp;; expand to all time steps</div>
<div>&nbsp; mask_3d = (data .eq. max_3d) &nbsp; &nbsp;; true at all values equal to point maximums</div>
<div>&nbsp;&nbsp;<br>
</div>
<div>&nbsp; inds_1d &nbsp; &nbsp; = ispan (0, ntimes-1, 1) &nbsp; &nbsp;; make data array of time indices</div>
<div>&nbsp; inds_3d &nbsp; &nbsp; = conform_dims (dims_3d, inds_1d, 0) &nbsp;; expand to all lat,lon</div>
<div>&nbsp; inds_3d@_FillValue = -999</div>
<div>&nbsp; inds_masked = where (mask_3d, inds_3d, inds_3d@_FillValue)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; time indices at all values equal to point maximums</div>
<div><br>
</div>
<div>; There may be two or more identical maximum values for any grid point.</div>
<div>; Just extract a single time index at each grid point.</div>
<div>; Grid points with no data are set to missing (_FillValue).</div>
<div><br>
</div>
<div>&nbsp; inds_max_2d = dim_min_n (inds_masked, 0) &nbsp; &nbsp; ; FIRST OCCURRENCE IN TIME</div>
<div>; &nbsp;inds_max_2d = dim_max_n (inds_masked, 0) &nbsp; &nbsp;; LAST &nbsp;OCCURRENCE IN TIME</div>
</div>
<div><br>
</div>
<div>Also, see attached working example, which plots the results.</div>
<div><br>
</div>
<div>--Dave</div>
<div><br>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Wed, Sep 9, 2015 at 9:22 PM, Kyle Griffin <span dir="ltr">
&lt;<a href="mailto:ksgriffin2@wisc.edu" target="_blank">ksgriffin2@wisc.edu</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div dir="ltr">Hi Matt,
<div><br>
</div>
<div>I think dim_max_n is what you're looking for.</div>
<div><br>
</div>
<div><a href="https://www.ncl.ucar.edu/Document/Functions/Built-in/dim_max_n.shtml" target="_blank">https://www.ncl.ucar.edu/Document/Functions/Built-in/dim_max_n.shtml</a><br>
</div>
<div><br>
</div>
<div>Not sure if I've used it in this manner before, but if you specify the dimension to find the max over (2nd argument) as 0, I think you should get what you're looking for. As a built-in function, it should be faster than looping over each point.</div>
<div><br>
</div>
<div><br>
</div>
<div>Kyle</div>
</div>
<div class="gmail_extra"><br clear="all">
<div>
<div>
<div dir="ltr">
<div>
<div dir="ltr">----------------------------------------
<div>Kyle S. Griffin</div>
<div>Department of Atmospheric and Oceanic Sciences</div>
<div>University of Wisconsin - Madison</div>
<div>Room 1407</div>
<div>1225 W Dayton St, Madison, WI 53706</div>
<div>Email: <a href="mailto:ksgriffin2@wisc.edu" target="_blank">ksgriffin2@wisc.edu</a></div>
</div>
</div>
</div>
</div>
</div>
<br>
<div class="gmail_quote">On Wed, Sep 9, 2015 at 9:08 PM, Matthew Fearon <span dir="ltr">
&lt;<a href="mailto:Matthew.Fearon@dri.edu" target="_blank">Matthew.Fearon@dri.edu</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div>
<div style="direction:ltr; font-family:Tahoma; color:#000000; font-size:10pt">Dear NCL Users,
<div><br>
</div>
<div>Trying to get the index of the maximum value on a single dimension as part of a multidimensional array. The array is data(time, lat, lon) where nlat x nlon is 400x500 and ntime=24. Would like the maximum over the time dimension for each grid cell or lat/long.
 Has anymore performed this without a loop over nlat/nlon ?</div>
<div><br>
</div>
<div>Making the array 1D (and using ind_resolve) allows me to get the max inds per dimension over the whole array, which isn't what I need.&nbsp;</div>
<div><br>
</div>
<div>Any suggestions would be greatly appreciated.&nbsp;</div>
<div>thanks,</div>
<div>Matt</div>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>