How to get the coordinates of the maximum in xarray?
问题 simple question: I don't only want the value of the maximum but also the coordinates of it in a xarray DataArray. How to do that? I can of course write my own simple reduce funtion, but I wonder if there is anything built-in in xarray? 回答1: You can use da.where() to filter based on the max value: In [15]: da = xr.DataArray(np.random.rand(2,3,4)) In [16]: da.where(da==da.max(), drop=True).squeeze() Out[16]: <xarray.DataArray (dim_0: 1, dim_1: 1, dim_2: 1)> array([[[ 0.91077406]]]) Coordinates: