tensors

a tensor is a generalization of vectors and matrices to potentially higher dimensions


when writing a tensorflow program, the main object you manipulate and pass around is the tf.Tensor. a tf.Tensor object represents a partially defined computation that will eventually produce a value. tensorflow programs work by first building a graph of tf.Tensor objects detailing how each tensor is commuted based on the other available tensors and then by running parts of this graph to achieve the desired results


each element in the tensor has the same data type, and the data type is always known


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


note that rank in tensorflow is not the same as matrix rank in mathematics


a string is treated as a single item in tensorflow, not as a sequence of characters. it is possible to have scalar strings, vectors of strings


to determine the rank of a tf.Tensor object, call the tf.rank method


###
my_row_vector = my_matrix[2]
my_column_vector = my_matrix[:, 3]


the : notation is python slicing syntax for "leave this dimension alone". this is useful in higher-rank tensors, as it allows you to access its subvectors, submatrices, and even other subtensors


the tensorflow documentation uses three notational conventions to describe tensor dimensionality: rank, shape, and dimension number


the number of elements of a tensor is the product of the sizes of all its shapes


it is possible to cast tf.Tensor from one datatype to another using tf.cast


once the computation graph has been built, you can run the computation that produces a particular tf.Tensor and fetch the value assigned to it


the simplest way to evaluate a tensor is using the Tensor.eval


sometimes it is not possible to evaluate a tf.Tensor with no context because its value might depend on dynamic information that is not available. for example, tensors that depend on placeholder can't be evaluated without providing a value for the placeholder


other model constructs might make evaluating a tf.Tensor complicated. tensorflow can't directly evaluate tf.Tensor defined inside functions or inside control flow constructs. if a tf.Tensor depends on a value from a queue, evaluating the tf.Tensor will only work once something has been enqueued; otherwise, evaluating it will hang. when working with queues, remember to call tf.train.start_queue_runners before evaluating any tf.Tensor

你可能感兴趣的:(Tensorflow)