pythonarraysnumpy

merging numpy arrays converts int to decimal


I am need to merge 2 arrays together

so if

a = [] 

and

b is array([76522, 82096], dtype=int64)

the merge will be [76522, 82096]

but i am getting this in a form of decimal

array([76522., 82096.])

here is my code

a = np.concatenate((a, b))

how can i merge both arrays with same datatype?


Solution

  • Since a is empty, when it gets converted to a numpy array, it chooses a default dtype=float64. Do the conversion explicitly so you can specify the dtype.

    np.concatenate((np.array(a, dtype=np.int64), b))