Computation¶
The labels associated with DataArray
and
Dataset
objects enables some powerful shortcuts for
computation, notably including aggregation and broadcasting by dimension
names.
Basic array math¶
Arithmetic operations with a single DataArray automatically vectorize (like numpy) over all array values:
In [1]: arr = xr.DataArray(np.random.RandomState(0).randn(2, 3),
...: [('x', ['a', 'b']), ('y', [10, 20, 30])])
...:
In [2]: arr - 3
Out[2]:
<xarray.DataArray (x: 2, y: 3)>
array([[-1.235948, -2.599843, -2.021262],
[-0.759107, -1.132442, -3.977278]])
Coordinates:
* x (x) <U1 'a' 'b'
* y (y) int64 10 20 30
In [3]: abs(arr)