mds_array_manipulation.sort_array
Module Contents
Functions
|
Sort a numpy array in ascending or alphabetical order. |
- mds_array_manipulation.sort_array.sort_array(arr: numpy.array) numpy.array[source]
Sort a numpy array in ascending or alphabetical order. The sorting is case-insensitive for strings. This function is specifically designed to work only with 1-dimensional arrays.
- Parameters:
arr (numpy.array) – The numpy array to be sorted. The array can contain numerical or string values.
- Returns:
A new numpy array sorted in ascending or alphabetical order.
- Return type:
numpy.array
- Raises:
TypeError – If the input is not a numpy array.
ValueError – If the input array is not 1-dimensional. This function does not support multi-dimensional arrays and will raise a ValueError if a multi-dimensional array is passed as input.
Examples
>>> import numpy as np >>> from mds_array_manipulation import mds_array_manipulation as am >>> arr = np.array([20, 10, 40, 30, 50, 90, 60]) >>> sort_array(arr) array([10, 20, 30, 40, 50, 60, 90])
>>> arr_str = np.array(["orange", "grape", "apple"]) >>> sort_array(arr_str) array(['apple', 'grape', 'orange'])