# Finding positions of minimum values in list

I would like to find the positions of multiple occurrences of a minimum value in a list. For instance, for the list {1, 2, 1, 3}, I want to obtain the two positions for the occurrences of the number 1.

MinimalBy[{1, 2, 1, 3}, id (x)] gives me these occurrences, but not the positions.

• MinimalBy[Range@Length@list, list[[#]] &]? May 2, 2019 at 3:05
• Or modifying this answer: minpos[a_] := SparseArray[UnitStep[# - a]]["AdjacencyLists"] &@Min@a and then minpos[list]. May 2, 2019 at 3:11
• Possible duplicate: mathematica.stackexchange.com/questions/40231/… May 2, 2019 at 3:13

lst = {1, 2, 1, 3};
RandomPrivatePositionsOf[lst, Min @ lst]


{1, 3}

Also

 Flatten@Position[lst, Min @ lst]


{1, 3}

list = {1, 2, 1, 3}
PositionIndex[list][Min[list]]


{1, 3}

• Even more appropriate for the task is: :PositionSmallest[list] Apr 26, 2023 at 6:46
• @MichaelWeyrauch You should write it as an answer. I am running v12.2.0 which is a few years old.
– Syed
Apr 26, 2023 at 11:45

o.k. as suggested by Syed, here comes my answer: As of Mathematica Version 13.2:

list={1,2,1,3}
PositionSmallest[list]


{1, 3}

Also there is:

PositionLargest[list]


{4}

• I love the new PositionSmallest and PositionLargest functions---significantly cleaner syntax for this common issue. I am left scratching my head, however, as to how it took until v13.x for them to be introduced... Apr 27, 2023 at 1:17