example:
"""
np.finfo使用方法
eps是一个很小的非负数
除法的分母不能为0的,不然会直接跳出显示错误。
使用eps将可能出现的零用eps来替换,这样不会报错。
"""
import numpy as np
x = np.array([1, 2, 3], dtype=float)
eps = np.finfo(x.dtype).eps # eps = 2.220446049250313e-16 type = <class 'numpy.float64'>
print(eps, type(eps))
height = np.array([0, 2, 3], dtype=float)
height = np.maximum(height, eps) #一旦height中出现0,就用eps进行替换
print(height) #[2.22044605e-16 2.00000000e+00 3.00000000e+00]
dy = x / height
print(dy) #[4.50359963e+15 1.00000000e+00 1.00000000e+00]
Undertake programming in Matlab, Python and C++, machine learning, computer vision theory implementation and guidance, both undergraduate and master's degree, salted fish trading, professional answers please go to know, please contact QQ number 757160542 for details, if you are the one.