larray.Array.sort_labels

Array.sort_labels(axes=None, ascending=True) Array[source]

Sort labels of axes of the array.

Parameters
axesaxis reference (Axis, str, int) or list of them, optional

Axes to sort the labels of. Defaults None (all axes).

ascendingbool, optional

Sort labels in ascending order. Defaults to True.

Returns
Array

Array with sorted labels.

Examples

>>> a = ndtest("nat=EU,FO,BE; sex=M,F")
>>> a
nat\sex  M  F
     EU  0  1
     FO  2  3
     BE  4  5
>>> a.sort_labels('sex')
nat\sex  F  M
     EU  1  0
     FO  3  2
     BE  5  4
>>> a.sort_labels()
nat\sex  F  M
     BE  5  4
     EU  1  0
     FO  3  2
>>> a.sort_labels(('sex', 'nat'))
nat\sex  F  M
     BE  5  4
     EU  1  0
     FO  3  2
>>> a.sort_labels(ascending=False)
nat\sex  M  F
     FO  2  3
     EU  0  1
     BE  4  5