WOLFRAM

gives the positions of the numerically largest value in list.

PositionLargest[list,n]

gives the positions of the first n largest values.

PositionLargest[list,n,orderfun]

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

Details

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

Examples

open allclose all

Basic Examples  (2)Summary of the most common use cases

Find positions of the largest value in a list:

Out[1]=1

Get lists of positions for the three largest values:

Out[1]=1

Scope  (6)Survey of the scope of standard use cases

Find positions of the two largest values in an association:

Out[1]=1

PositionLargest works with arbitrary numeric values:

Out[1]=1

PositionLargest can work with orderings of non-numeric data:

Out[1]=1

PositionLargest uses numeric ordering by default:

Out[1]=1

Instead use canonical ordering:

Out[2]=2

PositionLargest works on lists of Quantity expressions:

Out[1]=1
Out[2]=2

PositionLargest works on lists of DateObject expressions:

Out[1]=1
Out[2]=2

Properties & Relations  (4)Properties of the function, and connections to other functions

Find positions of the largest elements in a random list:

Out[22]=22

Compare to results using Position and Max:

Out[23]=23

PositionLargest gives positions of all the largest elements:

Out[1]=1

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

Out[2]=2

One must specify the count of maximal elements to get all positions corresponding to the largest element using TakeLargest:

Out[3]=3

Find positions of the largest elements in a random list:

Out[1]=1

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

Out[2]=2

Find positions of the largest elements in a random list:

Out[1]=1

FindPeaks locates positions of all local maximal values:

Out[2]=2

When you remove all peak positions that do not correspond to the global maximum value, you lose positions if there happen to be consecutive peaks:

Out[3]=3

Possible Issues  (2)Common pitfalls and unexpected behavior

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

Out[1]=1

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

Out[1]=1
Wolfram Research (2022), PositionLargest, Wolfram Language function, https://reference.wolfram.com/language/ref/PositionLargest.html.
Wolfram Research (2022), PositionLargest, Wolfram Language function, https://reference.wolfram.com/language/ref/PositionLargest.html.

Text

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

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

CMS

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

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

APA

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

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

BibTeX

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

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

BibLaTeX

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

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