Python 找到满足条件的xarray指数

Python 找到满足条件的xarray指数,python,python-xarray,Python,Python Xarray,我想得到满足某些条件的xarray数据数组的索引。在一个相关的线程中提供的关于如何找到最大值的位置的答案对我也不起作用。在我的例子中,我也想找出其他类型条件的位置,而不仅仅是最大值。以下是我尝试过的: h=xr.DataArray(np.random.randn(3,4)) h.where(h==h.max(),drop=True).squeeze() # This is the output I got: <xarray.DataArray ()> array(1.6606569

我想得到满足某些条件的xarray数据数组的索引。在一个相关的线程中提供的关于如何找到最大值的位置的答案对我也不起作用。在我的例子中,我也想找出其他类型条件的位置,而不仅仅是最大值。以下是我尝试过的:

h=xr.DataArray(np.random.randn(3,4))
h.where(h==h.max(),drop=True).squeeze()

# This is the output I got:
<xarray.DataArray ()>
array(1.66065694)
h=xr.DataArray(np.random.randn(3,4))
h、 其中(h==h.max(),drop=True).squence()
#这是我得到的输出:
阵列(1.66065694)

这不会返回我链接到的示例中所示的位置,即使我正在执行相同的命令。我不知道为什么。

我更新了链接示例,以便更清楚地显示索引。由于xarray不再添加默认索引,因此上一个示例将查找最大位置,但不显示索引。抄录如下:

In [17]: da = xr.DataArray(
             np.random.rand(2,3), 
             dims=list('ab'), 
             coords=dict(a=list('xy'), b=list('ijk'))
         )

In [18]: da.where(da==da.max(), drop=True).squeeze()
Out[18]:
<xarray.DataArray ()>
array(0.96213673)
Coordinates:
    a        <U1 'x'
    b        <U1 'j'
[17]中的
:da=xr.DataArray(
np.rand.rand(2,3),
dims=列表('ab'),
coords=dict(a=list('xy'),b=list('ijk'))
)
在[18]中:da.where(da==da.max(),drop=True)
出[18]:
阵列(0.96213673)
协调:
A.