Convert dtype from int64 to int32

Basically, I use python x32 bit to load a list object from a file containing several numpy arrays (previously stored inside the brine using python x64).

I can download them correctly and check the contents, but I cannot use them.

TypeError: Cannot cast array data from dtype('int64') to dtype('int32') 

How to convert an element type of arrays from a list to int32 so that I can use them with python x32.

An error occurred while trying to complete the following part:

 a=np.bincount(np.hstack(data['Y'])) 

Looking at what's inside data['Y'] enter image description here

+8
python numpy
source share
1 answer

As others have said, 32-bit versions of numpy still support 64-bit data types. But if you really need to convert to int32, you can use the astype function:

 >>> import numpy as np >>> x = np.array([1,2,3], dtype=np.int64) >>> x array([1, 2, 3]) >>> x.dtype dtype('int64') >>> y = x.astype(np.int32) >>> y array([1, 2, 3], dtype=int32) 
+6
source share

All Articles