Skip to content

Commit 9364449

Browse files
committed
Add an example to DataArray.stack
1 parent 66cb580 commit 9364449

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

xray/core/dataarray.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,24 @@ def stack(self, **dimensions):
781781
stacked : DataArray
782782
DataArray with stacked data.
783783
784+
Example
785+
-------
786+
787+
>>> arr = DataArray(np.arange(6).reshape(2, 3),
788+
... coords=[('x', ['a', 'b']), ('y', [0, 1, 2])])
789+
>>> arr
790+
<xray.DataArray (x: 2, y: 3)>
791+
array([[0, 1, 2],
792+
[3, 4, 5]])
793+
Coordinates:
794+
* x (x) |S1 'a' 'b'
795+
* y (y) int64 0 1 2
796+
>>> stacked = arr.stack(z=('x', 'y'))
797+
>>> stacked.indexes['z']
798+
MultiIndex(levels=[[u'a', u'b'], [0, 1, 2]],
799+
labels=[[0, 0, 0, 1, 1, 1], [0, 1, 2, 0, 1, 2]],
800+
names=[u'x', u'y'])
801+
784802
See also
785803
--------
786804
DataArray.unstack

0 commit comments

Comments
 (0)