Python numpy subtraction no negative numbers (4-6 gives 254)

戏子无情 提交于 2019-12-04 02:10:22

It sounds like the dtype of the array is uint8. All the numbers will be interpreted as integers in the range 0-255. Here, -2 is equal to 256 - 2, hence the subtraction results in 254.

You need to recast the arrays to a dtype which supports negative integers, e.g. int16 like this ...

face = face.astype(np.int16)

...and then subtract.

Sven

This is a problem with your datatype in the numpy array. You have a uint8 inside it, which seems to wrap around

Have a look at nfac.dtype whichwill show it to you. You have to convert it prior to your calculation operation. Use numpy.ndarray.astype to convert it or have a look at In-place type conversion of a NumPy array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!