Numpy Type(In)一致性?

时间:2014-10-15 09:58:01

标签: python numpy

在Numpy,我尝试了以下内容。我怀疑这不是一个错误。如果它是一个功能,我不明白。有人可以解释一下吗?感谢。

>>> np.array([173], dtype = np.uint8) * [360]
array([62280])
>>> np.array([173], dtype = np.uint8) * 360
array([-3256], dtype=int16)
>>> 

1 个答案:

答案 0 :(得分:1)

这些输出之间的差异可能是由您的numpy版本中的错误引起的。

代码

np.array([173], dtype = np.uint8) * [360]

是:

的简写
np.array([173], dtype = np.uint8) * np.array([360])
# output array([62280])

因此[360]被转换为dtype = int的numpy数组。乘法采用最高精度,因此返回具有int精度的数组。

相关问题