R's which() and which.min() Equivalent in Python
A simple loop will do:
res = []x = [1,2,3,4,0,1,2,3,4,11] for i in range(len(x)): if check_condition(x[i]): res.append(i)
One liner with comprehension:
res = [i for i, v in enumerate(x) if check_condition(v)]
Here you have a live example
NumPy for R provides you with a bunch of R functionalities in Python.
As to your specific question:
import numpy as npx = [1,2,3,4,0,1,2,3,4,11] arr = np.array(x)print(arr)# [ 1 2 3 4 0 1 2 3 4 11]print(arr.argmin(0)) # R's which.min()# 4print((arr==2).nonzero()) # R's which()# (array([1, 6]),)