Skip to content

largest, smallest #405

Open
Open
@Beliavsky

Description

@Beliavsky

I suggest adding a largest function so that largest(x(:),n) returns a 1D array containing the largest n elements of x in descending order. It would work for real and integer arrays and possibly arrays of character variables. For n > size(x) there would be a run-time error. A smallest function would return the smallest n elements in ascending order. Largest would have a subset of the functionality of maxk in Matlab.

Associated functions such as sum_largest(x,n) and mean_largest(x,n) could also be considered. In statistics, insurance, and finance, the properties of the n largest or smallest values of a sample are often studied.

middle(x,ntrim_min,ntrim_max,order) returning the values of x after removing the smallest ntrim_min and largest ntrim_max values could be considered. If optional argument order were omitted, the observations would be returned in the same order as x. If order="a" or order="d", the observations would be returned in ascending or descending order. The function middle would return a zero-sized array if size(x) < ntrim_min + ntrim_max. In a previous issue I suggested trimmed_mean. I think a function such as middle is more important, since trimmed_mean would be a byproduct.

ETA: maybe functions largest_loc, smallest_loc, and middle_loc, returning positions in x(:), are the first things to implement, since they are needed for largest, smallest, and middle. They would also have independent value. For two arrays x(:) and y(:) of equal size I often want the y values corresponding to the largest n values of x(:). I could use y(largest_loc(x,nlargest)).

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: algorithmssearching and sorting, merging, ...

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions