Select

Select[data,crit]

picks out all elements ei of data for which crit[ei] is True.

Select[data,critprop]

returns the property prop of the selected elements.

Select[data,crit,n]

picks out the first n elements for which crit[ei] is True.

Select[crit]

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

更多信息

  • Select keeps the elements for which the given criterion crit is True.
  • The data can have the following additional forms and interpretations:
  • {e1,e2,}list of values »
    f[e1,e2,]expression with any head f »
    Association[]association of values »
    QuantityArray[]quantity array or other structured array
    Tabular[]type-consistent tabular data »
    TabularColumn[]type-consistent column data »
    Dataset[]general hierarchical data
  • The property prop can have the following forms and interpretations:
  • "Element"the selected values »
    "Index"indices of the selected values »
    "BitVectorMask"Boolean mask returning True for slected values and False otherwise »
    {prop1,prop2,}a list of multiple forms »
    Allan association giving element, index and bit vector mask »
  • Select[crit][data] is equivalent to Select[data,crit].
  • Parallelize[Select[data,crit]] or ParallelSelect[data,crit] computes Select[data,crit] in parallel on all subkernels. »

范例

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

基本范例  (6)

选取偶数的元素:

Return the indices of the selected elements:

Return only the first expression selected:

Use the operator form of Select:

Select operates on values in an Association:

Select rows in a Tabular object:

范围  (15)

Basic Uses  (5)

Find pairs containing x:

Find up to 2 pairs containing x:

Fewer than the requested elements may be returned:

Use a pure function to test each element:

Use an operator form as selection criterion:

Use Select in operator form:

Input Data  (5)

Select works with any head, not just List:

Select works on values in Association:

Select works with SparseArray objects:

The result may be a list if it is not sparse:

Select works with TabularColumn objects:

Select all dates in November:

The distribution of the dates is uniform:

Use Select on a Tabular object with named columns:

Select rows with last column date being a business day:

Property Forms  (5)

Return the selected elements:

Return the indices of the selected elements:

Return the Boolean mask of the data:

Return two forms:

Return the association with all the properties:

应用  (7)

选取 100 以内满足对 3 和 5 求模为 1 的数:

选取正向和反向读取一致的 4 元数组:

求出前 4 个 3×3 的由 0 和 1 组成的矩阵,且它的行列式为 1 :

选择在单位圆以内的特征值:

求出内置 Wolfram 语言对象,它的名称小于 3 个字符:

从积中选取数值量:

求出 的近似值,其中点的比例在一个实心圆内:

属性和关系  (4)

Select is complementary to Discard:

SelectCases 相似,除了它使用的是一个函数而不是一个模式:

选取元素和小于 10 的列表:

Cases 获得相同的结果:

选择元素是偶数的:

Use GatherBy to separate odd and even elements:

Use GroupBy to construct an association explicitly containing as keys the results of the criterion:

并行计算 Select

可能存在的问题  (2)

Select picks out elements for which applying the criterion explicitly yields True:

The symbolic object x is not included in either case, since neither inequality gives True:

The head of the input expression is only preserved for the default "Element" property:

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

文本

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

CMS

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

APA

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

BibTeX

@misc{reference.wolfram_2025_select, author="Wolfram Research", title="{Select}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/Select.html}", note=[Accessed: 03-February-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_select, organization={Wolfram Research}, title={Select}, year={2025}, url={https://reference.wolfram.com/language/ref/Select.html}, note=[Accessed: 03-February-2025 ]}