numpy.maximum
SciPy.org에 있는 Numpy 관련 문법들이 등장할 때마다 정리해 두려고 한다.
* numpy.maximum
numpy.maximum(x1, x2, /, ...)
x1, x2 두개의 array 중 같은 index에 있는 최대 값을 output으로 출력해준다.
만약 x1.shape != x2.shape이면 common shape로 broadcasting 된다.
예시
>>> np.maximum([2, 3, 4], [1, 5, 2])
array([2, 5, 4])
>> np.maximum(np.eye(2), [0.5, 2]) # broadcasting
array([[1., 2.],
[0.5, 2.]])
>> np.maximum([np.nan, 0, np.nan], [0, np.nan, np.nan])
array([nan, nan, nan])
>> np.maximum(np.Inf, 1)
inf
여기서 np.eye(2), [0.5, 2]에 대해서만 설명해보면
np.eye(2) = [[1., 0.], 이고 [0.5, 2]는 broadcasting 되어서 [[0.5, 2], 가 된 것이다.
[0., 1.]] [0.5, 2]]
각자 index에서 최대값을 출력하면 위와 같은 결과가 된다.
출처: https://docs.scipy.org/doc/numpy/reference/generated/numpy.maximum.html
numpy.maximum — NumPy v1.17 Manual
Parameters: x1, x2 : array_like The arrays holding the elements to be compared. If x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output). out : ndarray, None, or tuple of ndarray and None, optional A loc
docs.scipy.org