TakeLargest

TakeLargest[data,n]

gives the n largest elements of data, sorted in descending order.

TakeLargest[dataprop,n]

gives the property prop for the n largest elements in data.

TakeLargest[data,n,p]

uses the ordering function p for sorting.

TakeLargest[n]

represents an operator form of TakeLargest that can be applied to an expression.

更多信息和选项

范例

打开所有单元关闭所有单元

基本范例  (4)

取列表中前两个最大的数:

用运算符形式的 TakeLargest 做同样的事:

Get the three largest quantities in a list of Quantity objects:

Quantities can be present in multiple units:

Get the two latest dates in a list of DateObject constructs:

Take the three largest values in an association:

范围  (9)

Take the four largest numbers, or as many as are available if fewer:

Quantities can be given as QuantityArray:

By default, Missing[] and several other symbolic expressions are excluded from the results:

Get the two largest elements in a list:

Get the positions of the two largest elements in a list:

Get the two largest elements in a list along with their positions:

Get the two largest elements in a list with their positions given first:

Get associations containing the element and position of the two largest elements in a list:

Find the three largest elements in a TabularColumn object:

Get the four rows with the largest elements in the first column in a Tabular object:

Ties in the first column are resolved by comparing values in the second column:

Take a list of numeric expressions or infinities:

By default, TakeLargest sorts the elements using NumericalOrder:

Use canonical Order instead:

Take a list of lists of integers:

They are not numeric elements, so they are sorted by default following canonical order:

Use instead lexicographic order, which will sort the list by their respective first elements:

Take a list of complex numbers:

Following reverse NumericalOrder, TakeLargest selects numbers with decreasing real part:

选项  (2)

ExcludedForms  (2)

By default, Missing[] and several other symbolic expressions are excluded from the results:

Specify which elements should be excluded:

By default, TakeLargest takes all elements into account when finding the largest ones:

Exclude particular elements:

Exclude elements matching a given pattern:

应用  (6)

Get the three planets with the largest radii:

Get the release dates of the five most recent James Bond movies:

Find the South American countries with the highest life expectancy for their inhabitants:

Find the codons (groups of three consecutive nucleotides) with the highest relative frequencies in the list of nucleotides of a gene:

Find the noble gases with the highest boiling point and density:

Find the five densest chemical elements:

属性和关系  (6)

TakeLargest[list,n,p] is effectively equivalent to Take[ReverseSort[list,p],n]:

TakeLargest uses NumericalOrder as default ordering function p:

Using canonical order can give different results:

With numerical inputs, the result of TakeLargest is determined by numerical comparisons:

Comparisons of non-numerical elements effectively follow canonical order:

Order is the default ordering function for Sort and ReverseSort:

TakeLargest[data,] operates at the first level of the input data:

If the input has several levels, it is still elements of the first level that will be sorted and extracted:

Unlike Max, TakeLargest does not return values at deeper levels:

When different numerical expressions have the same value, their original order will be preserved:

TakeLargest[list,n,p] is effectively equivalent to MaximalBy[list,Identity,n,p]:

Take a list of five dates in the current year:

Get the two latest of the dates with TakeLargest:

Get the second latest of the dates with RankedMax:

可能存在的问题  (2)

If fewer than the requested number of elements are present, TakeLargest will not evaluate:

Use UpTo to get as many elements as possible:

If the elements are not comparable, TakeLargest will not evaluate:

Wolfram Research (2015),TakeLargest,Wolfram 语言函数,https://reference.wolfram.com/language/ref/TakeLargest.html (更新于 2025 年).

文本

Wolfram Research (2015),TakeLargest,Wolfram 语言函数,https://reference.wolfram.com/language/ref/TakeLargest.html (更新于 2025 年).

CMS

Wolfram 语言. 2015. "TakeLargest." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2025. https://reference.wolfram.com/language/ref/TakeLargest.html.

APA

Wolfram 语言. (2015). TakeLargest. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/TakeLargest.html 年

BibTeX

@misc{reference.wolfram_2025_takelargest, author="Wolfram Research", title="{TakeLargest}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/TakeLargest.html}", note=[Accessed: 21-April-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_takelargest, organization={Wolfram Research}, title={TakeLargest}, year={2025}, url={https://reference.wolfram.com/language/ref/TakeLargest.html}, note=[Accessed: 21-April-2025 ]}