`Symbol` is help class used to represent the operator node in Graph.
`Symbol` acts as an interface for building graphs from different components like Variable, Functor and Group. `Symbol` is also exported to python front-end (while Graph is not) to enable quick test and deployment. Conceptually, symbol is the final operation of a graph and thus including all the information required (the graph) to evaluate its output value.
A `Tensor` is a symbolic handle to one of the outputs of an `Operation`. It does not hold the values of that operation's output, but instead provides a means of computing those values in a TensorFlow @{tf.Session}.
一个简单的使用样例如下:
```python
# Build a dataflow graph.
c=tf.constant([[1.0,2.0],[3.0,4.0]])
d=tf.constant([[1.0,1.0],[0.0,1.0]])
e=tf.matmul(c,d)
# Construct a `Session` to execute the graph.
sess=tf.Session()
# Execute the graph and store the value that `e` represents in `result`.
result=sess.run(e)
```
Tensor的一些主要成员变量和接口可以参考如下:
```python
@property
defop(self):
"""The `Operation` that produces this tensor as an output."""
returnself._op
@property
defdtype(self):
"""The `DType` of elements in this tensor."""
returnself._dtype
@property
defgraph(self):
"""The `Graph` that contains this tensor."""
returnself._op.graph
@property
defname(self):
"""The string name of this tensor."""
ifnotself._op.name:
raiseValueError("Operation was not named: %s"%self._op)
return"%s:%d"%(self._op.name,self._value_index)
@property
defdevice(self):
"""The name of the device on which this tensor will be produced, or None."""
returnself._op.device
```
TensorFlow的Tensor可以作为target被session来run,实际上是Tensor已经包含了所有的Graph信息,可以track data dependency。