python numpy np.finfo()函数 eps
生活随笔
收集整理的這篇文章主要介紹了
python numpy np.finfo()函数 eps
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
用法
finfo函數(shù)是根據(jù)括號(hào)中的類型來(lái)獲得信息,獲得符合這個(gè)類型的數(shù)型
例1:
import numpy as np a=np.array([[1],[2],[-1],[0]]) b=np.maximum(a,np.finfo(np.float32).eps) print(b)結(jié)果:
[[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是取非負(fù)的最小值。當(dāng)計(jì)算的IOU為0或?yàn)樨?fù)(但從代碼上來(lái)看不太可能為負(fù)),使用np.finfo(np.float32).eps來(lái)替換
doc
finfo(dtype)Machine limits for floating point types. 浮點(diǎn)類型的機(jī)器限制。Attributes 屬性 ---------- eps : floating point number of the appropriate typeThe smallest representable number such that ``1.0 + eps != 1.0``.適當(dāng)類型的浮點(diǎn)數(shù)最小的可表示數(shù)字,例如``1.0 + eps!= 1.0''。epsneg : floating point number of the appropriate typeThe smallest representable number such that ``1.0 - epsneg != 1.0``.適當(dāng)類型的浮點(diǎn)數(shù)最小的可表示數(shù)字,例如``1.0-epsneg!= 1.0''。iexp : intThe number of bits in the exponent portion of the floating pointrepresentation.浮點(diǎn)表示形式的指數(shù)部分中的位數(shù)。machar : MachArThe object which calculated these parameters and holds more detailedinformation.計(jì)算這些參數(shù)并保存更多詳細(xì)信息的對(duì)象。machep : intThe exponent that yields ``eps``.產(chǎn)生``eps''的指數(shù)。max : floating point number of the appropriate typeThe largest representable number.適當(dāng)類型的浮點(diǎn)數(shù)可表示的最大數(shù)字。maxexp : intThe smallest positive power of the base (2) that causes overflow.導(dǎo)致溢出的基極(2)的最小正功率。min : floating point number of the appropriate typeThe smallest representable number, typically ``-max``.適當(dāng)類型的浮點(diǎn)數(shù)最小的可表示數(shù)字,通常是“ -max”。minexp : intThe most negative power of the base (2) consistent with there beingno leading 0s in the mantissa.基數(shù)(2)的最大負(fù)冪與尾數(shù)中沒(méi)有前導(dǎo)0一致。negep : intThe exponent that yields ``epsneg``.產(chǎn)生``epsneg''的指數(shù)。nexp : intThe number of bits in the exponent including its sign and bias.指數(shù)中的位數(shù),包括其符號(hào)和偏差。nmant : intThe number of bits in the mantissa.尾數(shù)的位數(shù)。precision : intThe approximate number of decimal digits to which this kind of floatis precise.這種浮點(diǎn)數(shù)精確到的近似十進(jìn)制數(shù)字。resolution : floating point number of the appropriate typeThe approximate decimal resolution of this type, i.e.``10**-precision``.適當(dāng)類型的浮點(diǎn)數(shù)此類型的近似十進(jìn)制分辨率,即``10 **-precision''。tiny : floating point number of the appropriate typeThe smallest-magnitude usable number.適當(dāng)類型的浮點(diǎn)數(shù)最小幅度的可用數(shù)字。Parameters ---------- dtype : floating point type, dtype, or instanceThe kind of floating point data type to get information about.浮點(diǎn)類型,dtype或?qū)嵗@取有關(guān)信息的浮點(diǎn)數(shù)據(jù)類型的種類。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. 對(duì)于numpy的開發(fā)人員:不要在模塊級(jí)別實(shí)例化它。 這些參數(shù)的初始計(jì)算非常昂貴,并且會(huì)對(duì)導(dǎo)入時(shí)間產(chǎn)生負(fù)面影響。 這些對(duì)象被緩存,因此在函數(shù)內(nèi)重復(fù)調(diào)用finfo()不會(huì)有問(wèn)題。示例
>>> from numpy import * >>> f = finfo(float) # the numbers given are machine dependent # 給出的數(shù)字取決于機(jī)器>>> f.nmant, f.nexp # nr of bits in the mantissa and in the exponent# 尾數(shù)和指數(shù)中的位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 : 關(guān)于np.finfo函數(shù)
參考文章3:Numpy 中文用戶指南 3.1 數(shù)據(jù)類型
參考文章4:Python第三方庫(kù)——Numpy
總結(jié)
以上是生活随笔為你收集整理的python numpy np.finfo()函数 eps的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 语义分割简介
- 下一篇: python Numpy 中文用户指南