advanced patterns using np.clip with NaN values in NumPy 1.24
I just started working with After trying multiple solutions online, I still can't figure this out... I'm working with an scenario when using `np.clip` on an array that contains `NaN` values. The function seems to ignore the `NaN` entries, and I am not getting the expected output when I try to clip values outside a specified range. Hereโs the code Iโm working with: ```python import numpy as np data = np.array([1, 2, np.nan, 4, 5]) clipped_data = np.clip(data, 2, 4) print(clipped_data) ``` I expected the output to replace the values below 2 with 2 and values above 4 with 4, while keeping the `NaN` as is. However, the output I get is: ``` [ 2. 2. nan 4. 4.] ``` The `NaN` seems to be treated as `2`, which is not the behavior I want. I want the `NaN` to remain unchanged. Iโve checked the documentation and it doesnโt mention anything about `NaN` handling in `np.clip`. I tried using `np.nan_to_num(data, nan=np.nan)` before clipping, but this does not solve the scenario either. Is there a way to achieve the desired behavior? Am I missing something in how `np.clip` interacts with `NaN` values? Any examples would be super helpful.