Numpy Type(In)一致性?

Geo*_*hel 5 python numpy

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

>>> np.array([173], dtype = np.uint8) * [360]
array([62280])
>>> np.array([173], dtype = np.uint8) * 360
array([-3256], dtype=int16)
>>> 
Run Code Online (Sandbox Code Playgroud)

Pie*_*ter 1

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

代码

np.array([173], dtype = np.uint8) * [360]
Run Code Online (Sandbox Code Playgroud)

是以下形式的简写:

np.array([173], dtype = np.uint8) * np.array([360])
# output array([62280])
Run Code Online (Sandbox Code Playgroud)

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