Python/강좌
Python 예제 - Numpy 배열에서 0이 아닌 최소값 찾기
Numpy 배열에서 0이 아닌 최소값을 찾는 예제입니다. 2021. 12. 1 최초작성 # -*- coding: utf-8 -*- import numpy as np import numpy.ma as ma a = np.array([-1, 0, 1, 2, 3, 4, 5]) print(a) min_value = np.min(ma.masked_where(a == 0, a)) print( "0이 아닌 최소값 :", min_value ) # the position/index of non-zero minimum value in the array min_value_idx = np.argmin(ma.masked_where(a == 0, a)) print( "0이 아닌 최소값의 인덱스 : ", min_value_idx )..
2021. 12. 1. 21:24