张量与AutoGraph
张量与AutoGraph
首先,我们导入
import tensorflow as tf
张量表示数值的数组(可能是多维数组
x = tf.range(12)
x
<tf.Tensor: shape=(12,), dtype=int32, numpy=array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], dtype=int32)>
我们可以通过检查张量的
x.shape
TensorShape([12])
If we just want to know the total number of elements in a tensor, i.e., the product of all of the shape elements, we can inspect its size. Because we are dealing with a vector here, the single element of its shape is identical to its size.
tf.size(x)
<tf.Tensor: shape=(), dtype=int32, numpy=12>