python numpy np.finfo()函数 eps
生活随笔
收集整理的這篇文章主要介紹了
python numpy np.finfo()函数 eps
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
用法
finfo函數是根據括號中的類型來獲得信息,獲得符合這個類型的數型
例1:
import numpy as np a=np.array([[1],[2],[-1],[0]]) b=np.maximum(a,np.finfo(np.float32).eps) print(b)結果:
[[1.0000000e+00][2.0000000e+00][1.1920929e-07][1.1920929e-07]]例2:
ious = np.maximum(1.0 * inter_area / union_area, np.finfo(np.float32).eps)eps是取非負的最小值。當計算的IOU為0或為負(但從代碼上來看不太可能為負),使用np.finfo(np.float32).eps來替換
doc
finfo(dtype)Machine limits for floating point types. 浮點類型的機器限制。Attributes 屬性 ---------- eps : floating point number of the appropriate typeThe smallest representable number such that ``1.0 + eps != 1.0``.適當類型的浮點數最小的可表示數字,例如``1.0 + eps!= 1.0''。epsneg : floating point number of the appropriate typeThe smallest representable number such that ``1.0 - epsneg != 1.0``.適當類型的浮點數最小的可表示數字,例如``1.0-epsneg!= 1.0''。iexp : intThe number of bits in the exponent portion of the floating pointrepresentation.浮點表示形式的指數部分中的位數。machar : MachArThe object which calculated these parameters and holds more detailedinformation.計算這些參數并保存更多詳細信息的對象。machep : intThe exponent that yields ``eps``.產生``eps''的指數。max : floating point number of the appropriate typeThe largest representable number.適當類型的浮點數可表示的最大數字。maxexp : intThe smallest positive power of the base (2) that causes overflow.導致溢出的基極(2)的最小正功率。min : floating point number of the appropriate typeThe smallest representable number, typically ``-max``.適當類型的浮點數最小的可表示數字,通常是“ -max”。minexp : intThe most negative power of the base (2) consistent with there beingno leading 0s in the mantissa.基數(2)的最大負冪與尾數中沒有前導0一致。negep : intThe exponent that yields ``epsneg``.產生``epsneg''的指數。nexp : intThe number of bits in the exponent including its sign and bias.指數中的位數,包括其符號和偏差。nmant : intThe number of bits in the mantissa.尾數的位數。precision : intThe approximate number of decimal digits to which this kind of floatis precise.這種浮點數精確到的近似十進制數字。resolution : floating point number of the appropriate typeThe approximate decimal resolution of this type, i.e.``10**-precision``.適當類型的浮點數此類型的近似十進制分辨率,即``10 **-precision''。tiny : floating point number of the appropriate typeThe smallest-magnitude usable number.適當類型的浮點數最小幅度的可用數字。Parameters ---------- dtype : floating point type, dtype, or instanceThe kind of floating point data type to get information about.浮點類型,dtype或實例獲取有關信息的浮點數據類型的種類。See Also -------- numpy.lib.machar.MachAr :The implementation of the tests that produce this information. iinfo :The equivalent for integer data types.Notes ----- For developers of numpy: do not instantiate this at the module level. The initial calculation of these parameters is expensive and negatively impacts import times. These objects are cached, so calling ``finfo()`` repeatedly inside your functions is not a problem. 對于numpy的開發人員:不要在模塊級別實例化它。 這些參數的初始計算非常昂貴,并且會對導入時間產生負面影響。 這些對象被緩存,因此在函數內重復調用finfo()不會有問題。示例
>>> from numpy import * >>> f = finfo(float) # the numbers given are machine dependent # 給出的數字取決于機器>>> f.nmant, f.nexp # nr of bits in the mantissa and in the exponent# 尾數和指數中的位nr (52, 11) >>> f.machep # most negative n so that 1.0 + 2**n != 1.0 -52 >>> f.eps # floating point precision: 2**machep array(2.2204460492503131e-16) >>> f.precision # nr of precise decimal digits: int(-log10(eps)) 15 >>> f.resolution # 10**(-precision) array(1.0000000000000001e-15) >>> f.negep # most negative n so that 1.0 - 2**n != 1.0 -53 >>> f.epsneg # floating point precision: 2**negep array(1.1102230246251565e-16) >>> f.minexp # most negative n so that 2**n gives normal numbers -1022 >>> f.tiny # smallest usuable floating point nr: 2**minexp array(2.2250738585072014e-308) >>> f.maxexp # smallest positive n so that 2**n causes overflow 1024 >>> f.min, f.max # the most negative and most positive usuable floating number (-1.7976931348623157e+308, array(1.7976931348623157e+308))參考文章1:https://scipy.github.io/old-wiki/pages/Numpy_Example_List_With_Doc.html#finfo.28.29
參考文章2:Numpy : 關于np.finfo函數
參考文章3:Numpy 中文用戶指南 3.1 數據類型
參考文章4:Python第三方庫——Numpy
總結
以上是生活随笔為你收集整理的python numpy np.finfo()函数 eps的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 语义分割简介
- 下一篇: python Numpy 中文用户指南