TensorFlow 中的张量如何不可变? [英] How are tensors immutable in TensorFlow?

查看:38
本文介绍了TensorFlow 中的张量如何不可变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 TensorFlow 文档中阅读了以下句子:

I read the following sentence in the TensorFlow documentation:

除了 tf.Variable,张量的值是不可变的,这意味着仅在单个执行张量的上下文中有一个单一的价值.但是,两次评估相同的张量可以返回不同的值;例如张量可以是从磁盘读取数据,或生成随机数.

With the exception of tf.Variable, the value of a tensor is immutable, which means that in the context of a single execution tensors only have a single value. However, evaluating the same tensor twice can return different values; for example that tensor can be the result of reading data from disk, or generating a random number.

有人可以详细说明张量的不可变"方面吗?

Can someone elaborate a little bit on the "immutable" aspect of a Tensor?

  1. 不变性的范围"是什么,因为两次评估张量可能会返回不同的结果?
  2. 单次执行的上下文"是什么意思?

推荐答案

张量,不同于变量,可以比作数学方程.

Tensors, differently from variables, can be compared to a math equation.

当你说一个张量等于 2+2 时,它的值实际上不是 4,它是导致 2+2 值的计算指令,当你开始一个会话并执行它时,TensorFlow 运行需要返回的计算2+2 的值并为您提供输出.由于张量在计算,而不是结果,张量是不可变的

When you say a tensor equals 2+2, it's value is not actually 4, it's the computing instructions that leads to the value of 2+2 and when you start a session an execute it, TensorFlow runs the computations needed to return the value of 2+2 and gives you the output. And because of the tensor beeing the computations, rather than the the result, a tensor is immutable

现在回答您的问题:

  1. 说张量可以用不同的值来计算,这意味着如果你说一个张量等于一个随机数,当你运行它不同的时间时,你将有不同的值(作为方程本身是一个随机的),但前面提到的张量本身的值,不是值,是导致它的步骤(在这种情况下是一个随机公式)

  1. By saying the tensor can be evaluated with different values it means that if you for example say that a tensor equals to a random number, when you run it different times, you will have different values (as the equation itself is a random one), but the value of the tensor itself as mentioned before, is not the value, is the steps that leads to it (in this case a random formula)

单次执行的上下文意味着当你运行一个张量时,它只会输出一个值.认为执行张量就像应用我提到的方程一样.如果我说一个张量等于 random + 1,当你执行一次张量时,它会返回一个随机值 +1,没有别的.但由于张量包含随机输出,如果多次运行,很可能会得到不同的值

The context of a single execution means that when you run a tensor, it will only output you one value. Think executing a tensor like applying the equation i mentioned. If i say a tensor equals random + 1, when you execute the tensor a single time, it will return you a random value +1, nothing else. But since the tensor contains a randomic output, if you run it multiple times, you will most likely get different values

这篇关于TensorFlow 中的张量如何不可变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆