numpy.float和numpy.float64之间的区别

时间:2016-09-23 17:42:43

标签: python numpy types

numpy.float和numpy.float64之间似乎存在细微差别。

float MTF

有人可以澄清一下吗?感谢

2 个答案:

答案 0 :(得分:9)

np.float是python float类型的别名。 np.float32np.float64是numpy特定的32位和64位浮点类型。

float?
Init signature: float(self, /, *args, **kwargs)
Docstring:     
float(x) -> floating point number

Convert a string or number to a floating point number, if possible.
Type:           type

np.float?
Init signature: np.float(self, /, *args, **kwargs)
Docstring:     
float(x) -> floating point number

Convert a string or number to a floating point number, if possible.
Type:           type

np.float32?
Init signature: np.float32(self, /, *args, **kwargs)
Docstring:      32-bit floating-point number. Character code 'f'. C float compatible.
File:           c:\python\lib\site-packages\numpy\__init__.py
Type:           type

np.float64?
Init signature: np.float64(self, /, *args, **kwargs)
Docstring:      64-bit floating-point number. Character code 'd'. Python float compatible.
File:           c:\python\lib\site-packages\numpy\__init__.py
Type:           type

因此,当你执行isinstance(2.0, np.float)时,它等同于isinstance(2.0, float),因为2.0是一个普通的python内置浮点类型......而不是numpy类型。

isinstance(np.float64(2.0), np.float64)显然是True

答案 1 :(得分:-3)

这似乎是32位浮点数和64位浮点数之间的差异(在C中,浮点数与双精度数),2.0最终是32位浮点数