I saw a very strange behavior in numpy array, when I mixed int32 and int8 arrays in a simple operation, the int32 array element ct[4,0] seems to have become 8bit when taking the result of += dleng[4]*4:
import numpy as np
In[3]: ct = np.zeros((6,1), np.int32)
In[4]: ct
Out[4]:
array([[0],
[0],
[0],
[0],
[0],
[0]], dtype=int32)
In[5]: dleng = np.zeros((6, 1), np.int8)
In[6]: dleng[0] = 2
dleng[1] = 3
dleng[2] = 4
dleng[3] = 7
dleng[4] = 3
dleng[5] = 5
In[7]: dleng
Out[7]:
array([[2],
[3],
[4],
[7],
[3],
[5]], dtype=int8)
In[8]: ct[4] = 117
In[9]: ct
Out[9]:
array([[ 0],
[ 0],
[ 0],
[ 0],
[117],
[ 0]], dtype=int32)
In[10]: ct[4,0] += dleng[4]*4
In[11]: ct
Out[11]:
array([[ 0],
[ 0],
[ 0],
[ 0],
[-127],
[ 0]], dtype=int32)}
Does anyone know why this might happen?