如何在python中定义np.float128变量?

2024-04-28 14:15:47 发布

您现在位置:Python中文网/ 问答频道 /正文

在对问题Double precision floating values in Python?的最上浮的回答中提到,如果我们需要的精度超过标准浮点,我们可以使用np.float128。但是我找不到一个方法来做这件事

然后,在对how to declare variable type, C style in python投票最多的答案中,建议使用键入

然而,当我尝试使用类型化将整型值的数据类型设置为float时,Python仍然使用int数据类型

n : float=10000
print(type(n))

但结果仍然是:

<class 'int'>

那么,如何在python中定义np.float128类型变量呢


Tags: 方法in标准typenp精度floatprecision
1条回答
网友
1楼 · 发布于 2024-04-28 14:15:47

你试过以下方法吗

from numpy import float128

n=float128(10000)

print(type(n))

打印:

<class 'numpy.float128'>

请记住,在Windows 64位上使用numpy.float128会出现一些问题(请参见numpy.float128 doesn't exist in windows, but is called from OpenGL)。我已经在一个在线Python编辑器中测试了这段代码

相关问题 更多 >