title: King of the Center
body: <p>For a 3D volume of shape (N, K, L), what is the most pythonic way to get an index array of the following order:</p>
  <pre class="lang-py prettyprint-override"><code>[N//2, (N//2)-1, (N//2)+1, (N//2)-2, (N//2)+2, ..., (N//2)-(N//2)+1, (N//2)+((N//2)-1), 0]
  </code></pre>
  <p>Background:
  I have a binary 3D volume with a single complex 3D geometric object at its center (represented through <code>True</code> values). I would like to select the centermost slice <code>n</code> of the volume for which <code>np.any(vol[n,:,:])</code> returns <code>True</code>.</p>
  <p>I currently solve the issue as follows:</p>
  <pre class="lang-py prettyprint-override"><code># find the most centric slice that contains True values
  idx_t =  np.where(vol==True)[0]
  center = min(idx_t, key=lambda x : abs(max((vol.shape[0]-1)//2, 0) - x))
  </code></pre>
  <p>However, for larger volumes, using <code>np.where</code> seems quite wasteful. In particular, since the criterion is fulfilled by one of the three centermost slices in most cases. My idea is to instead iterate the slices using the array described above and exit the loop once a slice meets the criterion.</p>