Numeric equivalent of understanding if / else

Are there a few ways to do

n = [xt if x > 0 else x for x in nps] 

similar to this

 n = np.array(a) n[np.abs(n) < t] = 0 

Is something like this possible?

 n[n > 0] = nt 
+6
source share
1 answer

Verification failed, but try

 np.where(n > 0, n - t, n) 

See documentation

+10
source

Source: https://habr.com/ru/post/956284/


All Articles