numpy.core.defchararray.chararray.sort¶
- chararray.sort(axis=-1, kind='quicksort', order=None)¶
Sort an array, in-place.
Parameters: axis : int, optional
Axis along which to sort. Default is -1, which means sort along the last axis.
kind : {‘quicksort’, ‘mergesort’, ‘heapsort’}, optional
Sorting algorithm. Default is ‘quicksort’.
order : list, optional
When a is an array with fields defined, this argument specifies which fields to compare first, second, etc. Not all fields need be specified.
See also
- numpy.sort
- Return a sorted copy of an array.
- argsort
- Indirect sort.
- lexsort
- Indirect stable sort on multiple keys.
- searchsorted
- Find elements in sorted array.
- partition
- Partial sort.
Notes
See sort for notes on the different sorting algorithms.
Examples
>>> a = np.array([[1,4], [3,1]]) >>> a.sort(axis=1) >>> a array([[1, 4], [1, 3]]) >>> a.sort(axis=0) >>> a array([[1, 3], [1, 4]])
Use the order keyword to specify a field to use when sorting a structured array:
>>> a = np.array([('a', 2), ('c', 1)], dtype=[('x', 'S1'), ('y', int)]) >>> a.sort(order='y') >>> a array([('c', 1), ('a', 2)], dtype=[('x', '|S1'), ('y', '<i4')])