PositionSmallest

PositionSmallest[list]

gives the positions of the numerically smallest value in list.

PositionSmallest[list,n]

gives the positions of the first n smallest values.

PositionSmallest[list,n,orderfun]

gives the positions of the n smallest values in list as determined by orderfun.

Details

  • PositionSmallest by default compares values by numerical magnitude, returning the list of positions of the smallest value or n smallest values.
  • PositionSmallest[list] gives a single list for the smallest value.
  • PositionSmallest[list,n] gives a list of n sublists for the n smallest values, or as many as are available if fewer than n.
  • PositionSmallest expects all objects to be comparable with one another, based on the ordering function.

Examples

open allclose all

Basic Examples  (2)

Find positions of the smallest value in a list:

Get lists of positions for the three smallest values:

Scope  (6)

Find positions of the two smallest values in an association:

PositionSmallest works with arbitrary numeric values:

PositionSmallest can work with orderings of non-numeric data:

PositionSmallest uses numeric ordering by default:

Instead use canonical ordering:

PositionSmallest works on lists of Quantity expressions:

PositionSmallest works on lists of DateObject expressions:

Properties & Relations  (4)

Find positions of the smallest elements in a random list:

Compare to results using Position and Min:

PositionSmallest gives positions of all the smallest elements:

TakeSmallest will only give as many element positions as are requested:

One must specify the count of minimal elements to get all positions corresponding to the smallest element using TakeSmallest:

Find positions of the smallest elements in a random list:

One can use Ordering once the number of smallest elements is known:

Find positions of the smallest elements in a random list:

FindPeaks locates positions of all local minimal values:

Remove all peak positions that do not correspond to the global minimum value:

Possible Issues  (2)

If fewer than the requested count of smallest values are present, PositionSmallest will give as many as are present:

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

Wolfram Research (2022), PositionSmallest, Wolfram Language function, https://reference.wolfram.com/language/ref/PositionSmallest.html.

Text

Wolfram Research (2022), PositionSmallest, Wolfram Language function, https://reference.wolfram.com/language/ref/PositionSmallest.html.

CMS

Wolfram Language. 2022. "PositionSmallest." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/PositionSmallest.html.

APA

Wolfram Language. (2022). PositionSmallest. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/PositionSmallest.html

BibTeX

@misc{reference.wolfram_2024_positionsmallest, author="Wolfram Research", title="{PositionSmallest}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/PositionSmallest.html}", note=[Accessed: 21-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_positionsmallest, organization={Wolfram Research}, title={PositionSmallest}, year={2022}, url={https://reference.wolfram.com/language/ref/PositionSmallest.html}, note=[Accessed: 21-November-2024 ]}