How to define np.float128 variable in python?

你离开我真会死。 提交于 2021-02-10 22:18:24

问题


In the most upvoted answer to the question Double precision floating values in Python? it is mentioned that we can use np.float128, if we need precision more than standard float. But I couldn't find a way to do this.

Then, in the most upvoted answer to how to declare variable type, C style in python, use of typing is suggested.

However, when I tried to use typing to set the datatype as float for a integer type value, Python still used an int data type.

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

But still, the result is :

<class 'int'>

So, How can I define np.float128 type variable in python?


回答1:


Have you tried the following?

from numpy import float128

n=float128(10000)

print(type(n))

Print:

<class 'numpy.float128'>

Bear in mind that there are some issues using numpy.float128 on Windows 64-bit (see numpy.float128 doesn't exist in windows, but is called from OpenGL). I have tested this code in an online Python editor.



来源:https://stackoverflow.com/questions/63289402/how-to-define-np-float128-variable-in-python

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