Note

Numpy (33) 본문

Numpy

Numpy (33)

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

How to find the position of missing values in numpy array?

# 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])
iris_2d[np.random.randint(150, size=20), np.random.randint(4, size=20)] = np.nan

# Solution
print("Number of missing values: \n", np.isnan(iris_2d[:, 0]).sum())

# output
5

print("Position of missing values: \n", np.where(np.isnan(iris_2d[:, 0])))

# output
(array([ 39,  88,  99, 130, 147]),)

'Numpy' 카테고리의 다른 글

Numpy (35)  (0) 2022.08.27
Numpy (34)  (0) 2022.08.26
Numpy (32)  (0) 2022.08.24
Numpy (31)  (0) 2022.08.23
Numpy (30)  (0) 2022.08.22
Comments