In [4]:
import xarray as xr
import numpy as np

In [47]:
arr = xr.DataArray(np.arange(16).reshape(4, 4),[('x', ['a', 'b', 'c', 'd']), ('y', [10, 20, 30, 40])],name='sample')

In [48]:
arr.name


Out[48]:
'sample'

In [55]:
arr


Out[55]:
<xarray.DataArray 'sample' (x: 4, y: 4)>
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11],
       [12, 13, 14, 15]])
Coordinates:
  * x        (x) <U1 'a' 'b' 'c' 'd'
  * y        (y) int32 10 20 30 40

In [59]:
arr.mean(['x','y'])


Out[59]:
<xarray.DataArray 'sample' ()>
array(7.5)

In [26]:
arr+10


Out[26]:
<xarray.DataArray 'sample' (x: 4, y: 3)>
array([[10, 11, 12],
       [13, 14, 15],
       [16, 17, 18],
       [19, 20, 21]])
Coordinates:
  * x        (x) <U1 'a' 'b' 'c' 'd'
  * y        (y) int32 10 20 30

In [45]:
nan_arr = xr.DataArray([[0, 1, np.nan, np.nan, 2],[0, 1, np.nan, np.nan, 2]], dims=(['x', 'y']), name='1D_with_nan')

In [46]:
nan_arr


Out[46]:
<xarray.DataArray '1D_with_nan' (x: 2, y: 5)>
array([[  0.,   1.,  nan,  nan,   2.],
       [  0.,   1.,  nan,  nan,   2.]])
Coordinates:
  * x        (x) int64 0 1
  * y        (y) int64 0 1 2 3 4

In [33]:
nan_arr.isnull()


Out[33]:
<xarray.DataArray '1D_with_nan' (x: 5)>
array([False, False,  True,  True, False], dtype=bool)
Coordinates:
  * x        (x) int64 0 1 2 3 4

In [35]:
nan_arr.notnull()


Out[35]:
<xarray.DataArray '1D_with_nan' (x: 5)>
array([ True,  True, False, False,  True], dtype=bool)
Coordinates:
  * x        (x) int64 0 1 2 3 4

In [36]:
nan_arr.count()


Out[36]:
<xarray.DataArray '1D_with_nan' ()>
array(3)

In [39]:
nan_arr.dropna(dim='x')


Out[39]:
<xarray.DataArray '1D_with_nan' (x: 3)>
array([ 0.,  1.,  2.])
Coordinates:
  * x        (x) int64 0 1 4

In [42]:
nan_arr.fillna('a')


Out[42]:
<xarray.DataArray '1D_with_nan' (x: 5)>
array(['0.0', '1.0', 'a', 'a', '2.0'], 
      dtype='<U32')
Coordinates:
  * x        (x) int64 0 1 2 3 4

In [ ]: