title: How to find indices for sequential NaNs at the start and end of a1D NumPy array?
body: <p>I have a 1D NumPy array that contains both floating point numbers and NaNs. There will almost always be multiple sequential NaNs at the start and end of the array with some NaNs throughout the middle of the array. There is no way to predict in advance the location or number of NaNs present in the array.</p>
  <p>What I am trying to do:</p>
  <ul>
  <li>Retrieve indices of sequential NaNs occurring at the <strong>Start</strong> of the array and the <strong>End</strong> of the array only</li>
  <li>Not retrieve indices for NaNs in the middle of the array</li>
  <li>Avoid the use of loops/list comprehensions (if possible)</li>
  </ul>
  <p>Below is a short example illustrating the type of array I am working with (actual arrays will have 1e3 to 1e9 elements).</p>
  <pre><code>data = np.array([NaN, NaN, NaN, 1.2, 3.4, 5.0, NaN, 3.3, 3.2, NaN, NaN, 4.0, NaN, NaN, NaN, NaN])
  </code></pre>
  <p>For this array I would like to retrieve the following indices:</p>
  <pre><code>idx = [0, 1, 2, 12, 13, 14, 15]
  </code></pre>