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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值