numpy where
numpy.where 함수는 'x if condition else y' 같은 삼항식의 벡터화된 버전이다. import numpy as np xarr = np.array([1.1, 1.2, 1.3, 1.4, 1.5]) yarr = np.array([2.1, 2.2, 2.3, 2.4, 2.5]) cond = np.array([True, False, True, True, False]) result1 = [(x if c else y) for x, y, c, in zip(xarr, yarr, cond)] result2 = np.where(cond, xarr, yarr) result1 과 result2 는 arry([1.1, 2.2, 1.3, 1.4, 2.5]) 로 같은 결과를 얻을 수 있다. np.where의 두..
2019.11.10