In [2]:
import numpy as np
import pandas as pd
import xarray as xr

In [3]:
data = xr.DataArray(np.arange(24).reshape(4,3,2), [('lat', [10,20,30,40]), ('lon', [10,20,30]), ('time', [2000,2001])])

In [4]:
data


Out[4]:
<xarray.DataArray (lat: 4, lon: 3, time: 2)>
array([[[ 0,  1],
        [ 2,  3],
        [ 4,  5]],

       [[ 6,  7],
        [ 8,  9],
        [10, 11]],

       [[12, 13],
        [14, 15],
        [16, 17]],

       [[18, 19],
        [20, 21],
        [22, 23]]])
Coordinates:
  * lat      (lat) int32 10 20 30 40
  * lon      (lon) int32 10 20 30
  * time     (time) int32 2000 2001

In [12]:
data.sel(time=slice(2000,2000))


Out[12]:
<xarray.DataArray (lat: 4, lon: 3, time: 1)>
array([[[ 0],
        [ 2],
        [ 4]],

       [[ 6],
        [ 8],
        [10]],

       [[12],
        [14],
        [16]],

       [[18],
        [20],
        [22]]])
Coordinates:
  * lat      (lat) int32 10 20 30 40
  * lon      (lon) int32 10 20 30
  * time     (time) int32 2000

In [13]:
data2 = data*2

In [14]:
data2


Out[14]:
<xarray.DataArray (lat: 4, lon: 3, time: 2)>
array([[[ 0,  2],
        [ 4,  6],
        [ 8, 10]],

       [[12, 14],
        [16, 18],
        [20, 22]],

       [[24, 26],
        [28, 30],
        [32, 34]],

       [[36, 38],
        [40, 42],
        [44, 46]]])
Coordinates:
  * lat      (lat) int32 10 20 30 40
  * lon      (lon) int32 10 20 30
  * time     (time) int32 2000 2001

In [15]:
data2-data


Out[15]:
<xarray.DataArray (lat: 4, lon: 3, time: 2)>
array([[[ 0,  1],
        [ 2,  3],
        [ 4,  5]],

       [[ 6,  7],
        [ 8,  9],
        [10, 11]],

       [[12, 13],
        [14, 15],
        [16, 17]],

       [[18, 19],
        [20, 21],
        [22, 23]]])
Coordinates:
  * lat      (lat) int32 10 20 30 40
  * lon      (lon) int32 10 20 30
  * time     (time) int32 2000 2001

In [16]:
data


Out[16]:
<xarray.DataArray (lat: 4, lon: 3, time: 2)>
array([[[ 0,  1],
        [ 2,  3],
        [ 4,  5]],

       [[ 6,  7],
        [ 8,  9],
        [10, 11]],

       [[12, 13],
        [14, 15],
        [16, 17]],

       [[18, 19],
        [20, 21],
        [22, 23]]])
Coordinates:
  * lat      (lat) int32 10 20 30 40
  * lon      (lon) int32 10 20 30
  * time     (time) int32 2000 2001

In [17]:
def myfunc(x, axis=None, **kwargs):
    return x/2

In [24]:
data.isel(time=[1]).std()


Out[24]:
<xarray.DataArray ()>
array(6.904105059069326)

In [14]:
data


Out[14]:
<xarray.DataArray (lat: 4, lon: 3, time: 2)>
array([[[ 0,  1],
        [ 2,  3],
        [ 4,  5]],

       [[ 6,  7],
        [ 8,  9],
        [10, 11]],

       [[12, 13],
        [14, 15],
        [16, 17]],

       [[18, 19],
        [20, 21],
        [22, 23]]])
Coordinates:
  * lat      (lat) int32 10 20 30 40
  * lon      (lon) int32 10 20 30
  * time     (time) int32 2000 2001

In [ ]: