larray.Array.sort_values

Array.sort_values(key=None, axis=None, ascending=True) Array[source]

Sort values of the array.

Parameters
keyscalar or tuple or Group

Key along which to sort. Must have exactly one dimension less than ndim. Cannot be used in combination with axis argument. If both key and axis are None, sort array with all axes combined. Defaults to None.

axisint or str or Axis

Axis along which to sort. Cannot be used in combination with key argument. Defaults to None.

ascendingbool, optional

Sort values in ascending order. Defaults to True.

Returns
Array

Array with sorted values.

Examples

sort the whole array (no key or axis given)

>>> arr_1D = Array([10, 2, 4], 'a=a0..a2')
>>> arr_1D
a  a0  a1  a2
   10   2   4
>>> arr_1D.sort_values()
a  a1  a2  a0
    2   4  10
>>> arr_2D = Array([[10, 2, 4], [3, 7, 1]], 'a=a0,a1; b=b0..b2')
>>> arr_2D
a\b  b0  b1  b2
 a0  10   2   4
 a1   3   7   1
>>> # if the array has more than one dimension, sort array with all axes combined
>>> arr_2D.sort_values()
a_b  a1_b2  a0_b1  a1_b0  a0_b2  a1_b1  a0_b0
         1      2      3      4      7     10

Sort along a given key

>>> # sort columns according to the values of the row associated with the label 'a1'
>>> arr_2D.sort_values('a1')
a\b  b2  b0  b1
 a0   4  10   2
 a1   1   3   7
>>> arr_2D.sort_values('a1', ascending=False)
a\b  b1  b0  b2
 a0   2  10   4
 a1   7   3   1
>>> arr_3D = Array([[[10, 2, 4], [3, 7, 1]], [[5, 1, 6], [2, 8, 9]]],
...            'a=a0,a1; b=b0,b1; c=c0..c2')
>>> arr_3D
 a  b\c  c0  c1  c2
a0   b0  10   2   4
a0   b1   3   7   1
a1   b0   5   1   6
a1   b1   2   8   9
>>> # sort columns according to the values of the row associated with the labels 'a0' and 'b1'
>>> arr_3D.sort_values(('a0', 'b1'))
 a  b\c  c2  c0  c1
a0   b0   4  10   2
a0   b1   1   3   7
a1   b0   6   5   1
a1   b1   9   2   8

Sort along an axis

>>> arr_2D
a\b  b0  b1  b2
 a0  10   2   4
 a1   3   7   1
>>> # sort values along axis 'a'
>>> # equivalent to sorting the values of each column of the array
>>> arr_2D.sort_values(axis='a')
a*\b  b0  b1  b2
   0   3   2   1
   1  10   7   4
>>> # sort values along axis 'b'
>>> # equivalent to sorting the values of each row of the array
>>> arr_2D.sort_values(axis='b')
a\b*  0  1   2
  a0  2  4  10
  a1  1  3   7