0
我正在使用numpy
在python 2.7
下,並且想到使用以代表像2e315這樣的大數字。然而它被認爲是inf
,儘管它小於允許的最大表示,接近1e4932。爲什麼數字低於numpy中float128的最大值被視爲inf?
In [1]: import numpy as np
In [2]: np.finfo(np.float128)
Out[2]: finfo(resolution=1e-18, min=-1.18973149536e+4932, max=1.18973149536e+4932, dtype=float128)
In [3]: np.float128(2E315)
Out[3]: inf
前面的例子在pythonanywhere.com測試與python 2.7
和numpy 1.8.1
其具有以下特性:
$ uname -a
Linux harry-liveconsole4 4.4.0-83-generiC#106-Ubuntu SMP Mon Jun 26 17:54:43 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
我還測試了上面的例子在我的本地64位的機器,但遇到錯誤AttributeError: 'module' object has no attribute 'float128'
和我有numpy 1.8.0
那裏。
我錯過了什麼?我應該有什麼架構才能在python下有? 有沒有一種解決方法來代表這樣的大數字,而不是inf
,但是讓我們輸入它們呢?
您測試此在'python 2.7'下?因爲我得到不同的結果。對於'np.float128('2e315')'我仍然得到'inf'結果。 –
也是我的numpy版本是''1.8.1'' –
@CedricZoppolo是的,這對Python2 –