Convert dtype from int64 to int32

numpy, python

Solution

As others have said, 32-bit versions of numpy still support 64-bit dtypes. 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)

Problem

Basically, I am using python x32 bit to load from file a list object containing several numpy arrays (previously saved inside a pickle using python x64). I can load them properly and check the contents but I cannot use them. ``` TypeError: Cannot cast array data from dtype('int64') to dtype('int32') ``` How can I convert the arrays element type from within the list to int32 so I can use them with python x32. The error comes when I try to execute the following part: ``` a=np.bincount(np.hstack(data['Y'])) ``` Looking at what is inside `data['Y']`

Original source