How are tensors immutable in TensorFlow?

前端 未结 1 1281
-上瘾入骨i
-上瘾入骨i 2021-01-14 13:01

I read the following sentence in the TensorFlow documentation:

With the exception of tf.Variable, the value of a tensor is immutable, which means th

相关标签:
1条回答
  • 2021-01-14 13:55

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

    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

    Now for your questions:

    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)

    2. 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

    0 讨论(0)
提交回复
热议问题