tf.cast的使用

这些东西还是看官方文档才能理解的更加透彻。

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)
sess = tf.Session()
sess.run(tf.initialize_all_variables())
print (sess.run((ss)))

结果返回一个[1 1 1 1] 1*4的tensor,我的理解是开始是[2,4] 设置为axis=0 意思就是要改变第0个也就是2的维度,所以变为1,4.
[1,1,1,1]代表[5,6,7,8]的下标
tf.concat的理解:官方解释
concat(
    values
,
    axis
,
    name
='concat'
)

Concatenates the list of tensors values along dimension axis. If values[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的理解与上文相同
比如
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为2 shape为[1,5] [[ 2.66666675  3.33333325  4.          4.66666651  5.33333349]]
如果不设置,变为rank为1 变为5维向量[ 2.66666675  3.33333325  4.          4.66666651  5.33333349]




 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值