mds_array_manipulation.sort_array

Module Contents

Functions

sort_array(arr)

Sort a numpy array in ascending or alphabetical order.

mds_array_manipulation.sort_array.sort_array(arr)[source]

Sort a numpy array in ascending or alphabetical order. The sorting is case-insensitive for strings.

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.

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'])