7

I want a list

a = [2,4,5,2]

to give

b = [0, 3]

I know how to do it for when there is only a single min element, but not multiple min elements. example:

b = a.index(min(a))

This will give me b = 0.

0

2 Answers 2

11

Find the minimum value, then iterate the list with index using enumerate to find the minimum values:

>>> a = [2,4,5,2]
>>> min_value = min(a)
>>> [i for i, x in enumerate(a) if x == min_value]
[0, 3]
Sign up to request clarification or add additional context in comments.

2 Comments

@McGrady, just voted.
4

You can do that using numpy in the following way:

import numpy as np
a = np.array([2,4,5,2])
np.where(a==a.min())

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.