问题描述
文档说:
另外,定义了这些带有_ref后缀的类型的变体用于引用类型的张量.
这到底是什么意思?什么是引用类型张量,它们与标准张量有何不同?
What exactly does this mean? What are reference-typed tensors and how do they differ from standard ones?
推荐答案
引用类型的张量是可变的.创建引用类型张量的最常见方法是定义一个 tf.Variable
:定义一个初始值为 dtype tf.float32
的 tf.Variable
将创建一个引用类型dtype tf.float32_ref
的张量.您可以通过将引用类型张量作为第一个参数传递给 tf.assign()
来改变它.
A reference-typed tensor is mutable. The most common way to create a reference-typed tensor is to define a tf.Variable
: defining a tf.Variable
whose initial value has dtype tf.float32
will create a reference-typed tensor with dtype tf.float32_ref
. You can mutate a reference-typed tensor by passing it as the first argument to tf.assign()
.
(请注意,引用类型张量是当前 TensorFlow 版本中的一个实现细节.我们鼓励您使用更高级别的包装器,例如 tf.Variable
,它可能会迁移到未来可变状态的替代表示.)
(Note that reference-typed tensors are something of an implementation detail in the present version of TensorFlow. We'd encourage you to use higher-level wrappers like tf.Variable
, which may migrate to alternative representations for mutable state in the future.)
这篇关于在 Tensorflow 中,类型以 _ref 结尾的张量和不以 _ref 结尾的张量有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!