python에서 조건문 수정...
조회수 540회
질문을 간단하게 바꿨습니다.
NP1=[-100,-100]
NP2=[50,50]
CHNP=[1,1]
try:
CHNP[(NP1 < 0) & (NP2 > 0)] = 99999
except:
CHNP = CHNP
로 코딩을 짰을떄
CHNP[1], CHNP[2]값이 왜 99999로 세팅되지 않고 1로 똑같이 남아있는 이유를 알려주시면 감사하겠습니다.
1 답변
-
numpy array 여야 합니다.
>>> import numpy as np >>> np1 = np.array([-100, -100]) >>> np2 = np.array([50, 50]) >>> chnp = np.array([1,1]) >>> chnp[np1<0] array([1, 1]) >>> chnp[np2>0] array([1, 1]) >>> chnp[(np1<0) & (np2>0)] array([1, 1]) >>> chnp[(np1<0) & (np2>0)]=9999 >>> chnp array([9999, 9999])
댓글 입력