ArrayTools
|
sort rtable by row, column, or other 1-D slice
|
|
Calling Sequence
|
|
SortBy( rtable1D, options )
SortBy( rtable2D, column_or_row, index, options )
SortBy( rtableND, Indices, options )
|
|
Parameters
|
|
rtable1D
|
-
|
nonempty 1-D rtable of data
|
rtable2D
|
-
|
nonempty 2-D rtable of data
|
rtableND
|
-
|
nonempty rtable of data having one or more dimensions
|
column_or_row
|
-
|
either column or row, specifies if a column or row defines the sorting
|
index
|
-
|
An integer that specifies the specific column or row that will define the sorting
|
Indices
|
-
|
A list specifies the column, row, or 1-D slice that will define the sorting
|
|
|
|
|
Options
|
|
•
|
inplace: Either true or false, specifies if the sorted rtable is to be stored in the original rtable.
|
•
|
output: The type of output. The supported options are:
|
–
|
permutation: Returns the permutation list which is used to perform the sorting.
|
–
|
sorted: Returns the sorted rtable. This is the default.
|
–
|
list of any of the above options: Returns an expression sequence with the corresponding outputs, in the same order.
|
|
|
Description
|
|
•
|
The SortBy command sorts the given rtable using the specified column, row, or 1-D slice. For example, if is a Matrix consisting of rows and columns, will return the Matrix formed by sorting the rows of in such a way that the elements in column will be non-decreasing.
|
•
|
Any additional arguments to SortBy are passed as additional arguments to the base sort command. The keywords ascending and descending are also accepted.
|
•
|
For an rtable of arbitrary number of dimensions, say , the Indices list specifies the 1-D slice that defines the sorting. This list must have size , with elements consisting of a single instance of and integers.
|
•
|
For the 1-D case, is equivalent to .
|
•
|
For the 2-D case, is equivalent to and is equivalent to .
|
•
|
When the starting indices for the rtable are all , then negative indices (for indexing from the end) can be used in addition to positive ones. More precisely, for a dimension of size , the allowable indices are the integers (for indexing from the beginning) and (for indexing from the end).
|
•
|
When one or more dimensions of the rtable has starting index different than , then only absolute indices are allowed. More precisely, if a dimension has range , then the allowable indices are the integers .
|
•
|
If an rtable has starting indices different than and the sorting permutation is returned, the permutation will the same as if the rtable had its indices shifted to all start at .
|
•
|
The rtable must have rectangular storage.
|
|
|
Examples
|
|
|
Example 1
|
|
>
|
|
|
|
Example 2
|
|
>
|
|
>
|
|
>
|
|
|
|
Example 3
|
|
•
|
Custom sorting options can be passed:
|
>
|
|
>
|
|
>
|
|
|
|
Example 4
|
|
•
|
The unsorted rtable can be updated with the sorted version:
|
>
|
|
>
|
|
|
|
Example 5
|
|
•
|
Arrays with starting indices different than are accepted:
|
>
|
|
•
|
For this Array, "row 1" refers to what would be "row 2" if the starting indices were shifted to all be :
|
>
|
|
|
|
Example 6
|
|
•
|
Consider the following 3-D Array:
|
>
|
|
| |
•
|
The data can be sorted using any 1-D slice, and the sorting permutation can be returned in addition to or instead of the sorted Array. For example:
|
>
|
|
•
|
The sorted Array can be reproduced using this permutation :
|
>
|
|
|
|
|
Compatibility
|
|
•
|
The ArrayTools[SortBy] command was introduced in Maple 2023.
|
|
|
|
|
|
|