title: Find the indices of the center point of a data cube using xarray
body: <p>I'm trying to extract a 3D cube from a data array using <code>xarray</code> in Python but first I need to extract the 3D indices of the center point. I've tried using the code below but I am getting all 0 indices which I know is incorrect.</p>
  <pre><code>import numpy as np
  import xarray as xr
  
  arr3d = np.random.randint(-100, 100, size=(5, 5, 5))
  lev = np.array([0,1,2,3,4])
  lat = np.array([-1,0,2,3,4])
  lon = np.array([-175,-174, -172, -171, -170])
  da = xr.DataArray(
      data=arr3d,
  
      dims=[&quot;lev&quot;, &quot;lat&quot;, &quot;lon&quot;],
      coords=dict(
          lev=([&quot;lev&quot;], lev),
          lat=([&quot;lat&quot;], lat),
          lon=([&quot;lon&quot;], lon) ),
  )
  # desired point in space
  clat = 2 
  clon = -175
  alt = 4
  # assuming the min will be just 1 value
  indices = da.where(((da==lev) &amp; (da==clat) &amp; (da==clon)), drop=True).squeeze()
  print(indices.values)
  </code></pre>
  <p>The output: [], an empty list</p>
  <p>I do not get an error so the syntax is correct but I suspect that this is not the right way to extract the center point. I'm also looking for a way, if I can get the indices of the center point, how to extract a cube that is 1 cell away from this point.</p>