代码之家  ›  专栏  ›  技术社区  ›  Gilfoyle

tensorflow替换tensor中接近零的值

  •  1
  • Gilfoyle  · 技术社区  · 6 年前

    我想避免我的代码中包含许多除法的数值不稳定性。如何用预先定义的数值稳定器替换张量中的小值?

    让稳定器 EPS=1e-9 . T 是一个张量,它包含许多接近零的小值。我想替换间隔内的所有值 [-EPS,EPS] 具有 EPS . 我该怎么做?

    1 回复  |  直到 6 年前
        1
  •  2
  •   javidcf    6 年前

     my_tensor_stable = tf.where(tf.abs(my_tensor) < EPS,
                                 EPS * tf.ones_like(my_tensor),
                                 my_tensor)