我有一個陣列,數字范圍從(-infinite 到 infinite)
代碼看起來像這樣:
delta_up = np.where(delta > 0, delta, 0)
delta_down = np.where(delta < 0, delta, 0)
問題:我的陣列中也有 nan,它們需要保留為 nan。但是他們正在被轉換為 0
如何解決?
uj5u.com熱心網友回復:
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]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/537826.html
