TakeSmallest

TakeSmallest[data,n]

gives the n smallest elements of data, sorted in ascending order.

TakeSmallest[dataprop,n]

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

TakeSmallest[data,n,p]

uses the order function p for sorting.

TakeSmallest[n]

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

更多信息和选项

范例

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

基本范例  (4)

提取列表中两个最小的数字:

利用 TakeSmallest 的运算符形式完成同样计算:

Quantity 对象列表中,获取最小的两个量:

可以出现不同的单位:

DateObject 构造列表中,获取两个最早的日期:

Take the three smallest values in an association:

范围  (9)

Take the four smallest 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 smallest elements in a list:

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

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

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

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

Find the three smallest elements in a TabularColumn:

Get the four rows with the smallest element in the first column in a Tabular object:

Take a list of numeric expressions or infinities:

By default, TakeSmallest 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 NumericalOrder, TakeSmallest 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, TakeSmallest takes all elements into account when finding the smallest ones:

Exclude particular elements:

Exclude elements matching a given pattern:

应用  (6)

Get the three planets with the smallest radii:

Get the release dates of the five oldest James Bond movies:

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

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

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

Find the five least dense chemical elements:

属性和关系  (6)

TakeSmallest[list,n,p] is effectively equivalent to Take[Sort[list,p],n]:

TakeSmallest uses NumericalOrder as default ordering function p:

Using canonical order can give different results:

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

Comparisons of non-numerical elements effectively follow canonical order:

Order is the default ordering function for Sort and ReverseSort:

TakeSmallest[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 Min, TakeSmallest does not return values at deeper levels:

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

TakeSmallest[list,n,p] is effectively equivalent to MinimalBy[list,Identity,n,p]:

Take a list of five dates in the current year:

Get the two earliest of the dates with TakeSmallest:

Get the second earliest of the dates with RankedMin:

可能存在的问题  (2)

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

Use UpTo to get as many elements as possible:

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

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

文本

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

CMS

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

APA

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

BibTeX

@misc{reference.wolfram_2025_takesmallest, author="Wolfram Research", title="{TakeSmallest}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/TakeSmallest.html}", note=[Accessed: 06-July-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_takesmallest, organization={Wolfram Research}, title={TakeSmallest}, year={2025}, url={https://reference.wolfram.com/language/ref/TakeSmallest.html}, note=[Accessed: 06-July-2025 ]}