简体   繁体   中英

find all elements > 0 in a np.array with np.where

I have a Array with Numbers ranging from (-infinite to +infinite)

Code looks like that:

delta_up = np.where(delta > 0, delta, 0)
delta_down = np.where(delta < 0, delta, 0)

Problem: I also have nan's in the array and they need to stay as nan's. But they are beeing converted to 0

How to solve it?

my_array = np.array([1, 2, 3, 5, -1, -2, -3, None], dtype="float")


negative_idx = np.where(my_array<0) # np.nan values will be ignore
positive_idx = np.where(my_array>0) # np.nan values will be ignore

# getting subarray with values `array[indexes]`
negative_values = my_array[negative_idx]
positive_values = my_array[positive_idx] 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM