4

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.

ExpressionCoder
  • 1,678
  • 7
  • 15

3 Answers3

6
lst = {1, 2, 1, 3};
Random`Private`PositionsOf[lst, Min @ lst]

{1, 3}

Also

 Flatten@Position[lst, Min @ lst]

{1, 3}

kglr
  • 394,356
  • 18
  • 477
  • 896
3
list = {1, 2, 1, 3}
PositionIndex[list][Min[list]]

{1, 3}

Syed
  • 52,495
  • 4
  • 30
  • 85
3

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}

Michael Weyrauch
  • 821
  • 5
  • 10
  • 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... – erfink Apr 27 '23 at 01:17