这些东西还是看官方文档才能理解的更加透彻。
cast(x, dtype, name=None)
将x的数据格式转化成dtype.例如,原来x的数据格式是bool,
官方解释https://www.tensorflow.org/api_docs/python/tf/cast
tf.argmax
官方解释:
argmax(
input,
axis=None,
name=None,
dimension=None,
output_type=tf.int64
)
Returns the index with the largest value across axes of a tensor. (deprecated arguments)
input是一个必须是int,必须再[-rank[input],rank[input]]之间,
返回一个Tensor。
举例
ss = tf.argmax([[1,2,3,4],[5,6,7,8]],0)
结果返回一个[1 1 1 1] 1*4的tensor,我的理解是开始是[2,4] 设置为axis=0 意思就是要改变第0个也就是2的维度,所以变为1,4.sess = tf.Session() sess.run(tf.initialize_all_variables()) print (sess.run((ss)))
[1,1,1,1]代表[5,6,7,8]的下标
tf.concat的理解:官方解释
concat(
values,
axis,
name='concat'
)
Concatenates the list of tensors
values
along dimensionaxis
. Ifvalues[i].shape = [D0, D1, ... Daxis(i), ...Dn]
, the concatenated result has shape
[D0, D1, ... Raxis, ...Dn]
where
Raxis = sum(Daxis(i))
t1 = [[1, 2, 3], [4, 5, 6]]
t2 = [[7, 8, 9], [10, 11, 12]]
tf.concat([t1, t2], 0) # [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
tf.concat([t1, t2], 1) # [[1, 2, 3, 7, 8, 9], [4, 5, 6, 10, 11, 12]]
# tensor t3 with shape [2, 3]
# tensor t4 with shape [2, 3]
tf.shape(tf.concat([t3, t4], 0)) # [4, 3]
tf.shape(tf.concat([t3, t4], 1)) # [2, 6]我的理解就是concat[t1,t2],0 意思就是要修改第0个数的维度,所以将第0个数相加。tf.reducemean()
reduce_mean(
input_tensor,
axis=None,
keep_dims=False,
name=None,
reduction_indices=None
)按照axis来计算平均值,如果keep_dims=False,将会变成一个一维向量。如果为ture只有设置的axis变为一维。对于axis的理解与上文相同
比如
最后变成rank为2 shape为[1,5] [[ 2.66666675 3.33333325 4. 4.66666651 5.33333349]]t = tf.reduce_mean([[1.0,2,3,4,5],[6,7,8,9,10],[1,1,1,1,1]],axis=0,keep_dims=True)
如果不设置,变为rank为1 变为5维向量[ 2.66666675 3.33333325 4. 4.66666651 5.33333349]