Sort a Data Set

sorted_list(data)

Sorts all elements in a data set in increasing order via quicksort

Parameters

data (list of int or float) – List of numbers to analyze

Returns

order – List of all elements from a data set sorted in increasing order

Return type

list of int or float

Notes

  • Set of numbers: \(a_i = \{ a_1, a_2, \cdots, a_n \}\)

  • Sorted version of set: \(A_i = ( A_1, A_2, \cdots, A_n )\)

    • For all terms in \(A_i\): \(A_{n-1} \leq A_n\)

  • Monotonic Function

Examples

Import sorted_list function from regressions library
>>> from regressions.statistics.sort import sorted_list
Sort the set [5, 2, 9, 8]
>>> order_1 = sorted_list([5, 2, 9, 8])
>>> print(order_1)
[2, 5, 8, 9]
Sort the set [11, 3, 52, 25, 21, 25, 6]
>>> order_2 = sorted_list([11, 3, 52, 25, 21, 25, 6])
>>> print(order_2)
[3, 6, 11, 21, 25, 25, 52]
sorted_dimension(data, dimension=1)

Sorts all elements in a multidimensional data set in increasing order, according to particular dimension

Parameters
  • data (list of lists of int or float) – List of lists of numbers to analyze

  • dimension (int, default=1) – Number representing the dimension to use for sorting

Returns

order – List of lists of numbers sorted in increasing order, based on only one dimension of the nested list

Return type

list of lists of int or float

Notes

  • Set of ordered pairs of numbers: \(a_i = \{ ( a_{1,1}, a_{1,2}, \cdots, a_{1,j}, a_{1,n} ), ( a_{2,1}, a_{2,2}, \cdots, a_{2,j}, a_{2,n} ), \cdots, \\ ( a_{m,1}, a_{m,2}, \cdots, a_{m,j}, a_{m,n} ) \}\)

  • Sorted version of set according to the values in the \(j\)th position: \(A_i = ( ( A_{1,1}, A_{1,2}, \cdots, A_{1,j}, A_{1,n} ), ( A_{2,1}, A_{2,2}, \cdots, A_{2,j}, A_{2,n} ), \cdots, \\ ( A_{m,1}, A_{m,2}, \cdots, A_{m,j}, A_{m,n} ) )\)

    • For all terms in \(A_i\): \(A_{n-1,j} \leq A_{n,j}\)

  • Monotonic Function

Examples

Import sorted_dimension function from regressions library
>>> from regressions.statistics.sort import sorted_dimension
Sort the set [[1, 3, 5], [9, 2, 4], [6, 1, 8]] according to its second dimension
>>> order_1 = sorted_dimension([[1, 3, 5], [9, 2, 4], [6, 1, 8]], 2)
>>> print(order_1)
[[6, 1, 8], [9, 2, 4], [1, 3, 5]]
Sort the set [[1, 3, 5], [9, 2, 4], [6, 1, 8]] according to its third dimension
>>> order_2 = sorted_dimension([[1, 3, 5], [9, 2, 4], [6, 1, 8]], 3)
>>> print(order_2)
[[9, 2, 4], [1, 3, 5], [6, 1, 8]]