Note

Numpy (34) 본문

Numpy

Numpy (34)

알 수 없는 사용자 2022. 8. 26. 00:00
728x90

How to filter a numpy array based on two or more conditions?

# Input
url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data'
iris_2d = np.genfromtxt(url, delimiter=',', dtype='float', usecols=[0,1,2,3])

# Solution
condition = (iris_2d[:, 2] > 1.5) & (iris_2d[:, 0] < 5.0)
iris_2d[condition]

# output
 array([[ 4.8,  3.4,  1.6,  0.2],
        [ 4.8,  3.4,  1.9,  0.2],
        [ 4.7,  3.2,  1.6,  0.2],
        [ 4.8,  3.1,  1.6,  0.2],
        [ 4.9,  2.4,  3.3,  1. ],
        [ 4.9,  2.5,  4.5,  1.7]])

'Numpy' 카테고리의 다른 글

Numpy (36)  (0) 2022.08.28
Numpy (35)  (0) 2022.08.27
Numpy (33)  (0) 2022.08.25
Numpy (32)  (0) 2022.08.24
Numpy (31)  (0) 2022.08.23
Comments