Modify conditional statements in python...

Asked 2 years ago, Updated 2 years ago, 24 views

I simply changed the question.

NP1=[-100,-100]
NP2=[50,50]
CHNP=[1,1]

try:
    CHNP[(NP1 < 0) & (NP2 > 0)] = 99999
except:
    CHNP = CHNP

When you made the recordings.

I would appreciate it if you could tell me why the values of CHNP[1] and CHNP[2] are not set to 999999 and remain the same as 1.

python

2022-09-22 15:33

1 Answers

Must be a 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])


2022-09-22 15:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.