Unexpected dtype change when using np.concatenate with mixed array types in NumPy 1.24.3
I can't seem to get I'm working with an scenario with `np.concatenate` when trying to merge arrays of different dtypes... I have two arrays: one is an integer array, and the other is a float array. When I concatenate them, I expect the result to be of type float, but it seems to be converting the entire array to integers instead, which leads to data loss. Hereβs the code Iβm using: ```python import numpy as np arr_int = np.array([1, 2, 3]) arr_float = np.array([4.5, 5.5, 6.5]) result = np.concatenate((arr_int, arr_float)) print(result) print(result.dtype) ``` When I run this, I get the output: ``` [1. 2. 3. 4.5 5.5 6.5] float64 ``` which is what I expect, but when I try to concatenate the arrays in a different order like this: ```python result = np.concatenate((arr_float, arr_int)) ``` I get the unexpected output: ``` [4 5 6] dtype('int64') ``` This confuses me, as I assumed the output dtype would be float regardless of the order of the input arrays. I need the output to maintain the float dtype in both cases. Is there a specific reason for this behavior or a way to enforce the dtype I want? I've tried explicitly setting the dtype during concatenation with no success. Any insights would be greatly appreciated! Is there a better approach? Any feedback is welcome! Thanks for any help you can provide! I'm coming from a different tech stack and learning Python. I'd be grateful for any help.