Python 使用多个if替换xarray数据集的值

Python 使用多个if替换xarray数据集的值,python,python-3.x,machine-learning,deep-learning,python-xarray,Python,Python 3.x,Machine Learning,Deep Learning,Python Xarray,我有一个带有变量tas的xarray数据集,我想使用多个if条件更改其值。i、 e如果值大于0.1,则为1;如果值小于-0.1,则为-1;否则为0。我知道如何在单if条件下执行此操作: xr.where(df>0.1, 1, 0) 但是有人能告诉我如何使用多if条件来实现吗 xarray数据集: <xarray.Dataset> Dimensions: (lat: 90, lon: 720, time: 1200) Coordinates: * lon

我有一个带有变量tas的xarray数据集,我想使用多个if条件更改其值。i、 e如果值大于0.1,则为1;如果值小于-0.1,则为-1;否则为0。我知道如何在单if条件下执行此操作:

xr.where(df>0.1, 1, 0)
但是有人能告诉我如何使用多if条件来实现吗

xarray数据集:

<xarray.Dataset>
Dimensions:        (lat: 90, lon: 720, time: 1200)
Coordinates:
* lon            array([-90.      , -89.057592, -88.115183, -87.172775, -86.230366, -85.287958,
 -84.34555 , -83.403141, -82.460733, -81.518325, -80.575916, -79.633508,.... 85.287958, 89.057592,  90.])

* lat            array([  0.  ,   1.25,   2.5 , ..., 356.25, 357.5 , 358.75])

* time           array([cftime.DatetimeNoLeap(0001-01-15 12:00:00),
       cftime.DatetimeNoLeap(0001-02-14 00:00:00),
       cftime.DatetimeNoLeap(0001-03-15 12:00:00), ...,
       cftime.DatetimeNoLeap(1200-10-15 12:00:00),
       cftime.DatetimeNoLeap(1200-11-15 00:00:00),
       cftime.DatetimeNoLeap(1200-12-15 12:00:00)], dtype=object)

Data variables:
tas              (time, lat, lon) float32 ...

尺寸:(纬度:90,经度:720,时间:1200)
协调:
*lon阵列([-90、-89.057592、-88.115183、-87.172775、-86.230366、-85.287958、,
-84.34555 , -83.403141, -82.460733, -81.518325, -80.575916, -79.633508,.... 85.287958, 89.057592,  90.])
*横向阵列([0,1.25,2.5,…,356.25357.5358.75])
*时间数组([cftime.DatetimeNoLeap(0001-01-15 12:00:00),
cftime.DatetimeNoLeap(0001-02-14 00:00:00),
cftime.DatetimeNoLeap(0001-03-15 12:00:00)。。。,
cftime.DatetimeNoLeap(1200-10-15 12:00:00),
cftime.DatetimeNoLeap(1200-11-15 00:00:00),
cftime.DatetimeNoLeap(1200-12-15 12:00:00)],dtype=object)
数据变量:
tas(时间、纬度、经度)浮动32。。。

查看关于嵌套np.where()子句的以下答案:。这可能会帮助你做你需要的事情。