Skip to main content
 首页 » 编程设计

python之`tf.reciprocal` 与 `tf.inv` : is there any difference

2024年09月07日8zhoujg

tf.reciprocal 和 tf.inv 似乎是等价的。有什么不同吗?它们是作为单独的 TF 操作实现的,并且还具有单独的梯度实现,这看起来也是等效的。

请您参考如下方法:

意思是一样的。事实上,tf.inv 已重命名为 tf.reciprocal和 tf.inv 在最新版本中不再暴露给顶级模块(尽管两者仍然存在于 gen_math_ops.py 中)。

来自migration documentation :

Many functions have been renamed to match NumPy. This was done to make the transition between NumPy and TensorFlow as easy as possible. There are still numerous cases where functions do not match, so this is far from a hard and fast rule, but we have removed several commonly noticed inconsistencies.

  • tf.inv
    • should be renamed to tf.reciprocal
    • This was done to avoid confusion with NumPy's matrix inverse np.inv

您可以看到还有几个重命名的函数,例如 tf.mul 和 tf.neg。