advanced patterns when using np.clip with non-integer array in NumPy 1.24.0
Does anyone know how to I'm prototyping a solution and I've searched everywhere and can't find a clear answer... I'm working with an scenario with `np.clip` when applying it to a non-integer array. I have a 1D NumPy array of floating-point numbers, and I want to restrict its values between a specified minimum and maximum. However, the output array seems to be rounded to integers unexpectedly, leading to loss of precision in my data. Here's a snippet of my code: ```python import numpy as np def clip_values(arr, min_val, max_val): return np.clip(arr, min_val, max_val) data = np.array([0.1, 1.5, 3.2, 4.8, 2.2]) result = clip_values(data, 1.0, 3.0) print(result) # Expected output: [1.0, 1.5, 3.0] ``` However, when I run this, I'm getting the following output: ``` [1. 1. 3.] ``` It seems like the values are being converted to integers. I suspect it might be related to data types, but I'm not sure how to ensure that the output maintains the float representation. I've also checked the data types with `data.dtype` before clipping and confirmed it as `float64`. Can anyone explain why this is happening and how I can fix it to retain the floating-point precision in the output? What's the best practice here? The project is a REST API built with Python. Is there a simpler solution I'm overlooking?