Numpy

Numpy (46)

알 수 없는 사용자 2022. 9. 12. 01:59
728x90

How to find the position of the first occurrence of a value greater than a given value?

# Input:
url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data'
iris = np.genfromtxt(url, delimiter=',', dtype='object')

# Solution: (edit: changed argmax to argwhere. Thanks Rong!)
np.argwhere(iris[:, 3].astype(float) > 1.0)[0]

# output
50