TensorFlow 中重复输入向量指定维度内容 tf.tile 的基本用法及实例代码

一、环境

TensorFlow API r1.12

CUDA 9.2 V9.2.148

cudnn64_7.dll

Python 3.6.3

Windows 10

 

二、官方说明

根据指定的维度重复输入张量多次

https://tensorflow.google.cn/api_docs/python/tf/tile

输出的第 i 维具有 input.dims(i) * multiples[i] 个元素

输入值沿着维度 i 被重复 multiples[i] 次

tf.tile(
    input,
    multiples,
    name=None
)

参数:

input:1 维及1 维以上的张量 

multiples:张量,必须为 int32 或 int64 类型,长度必须与 input 的维度数量相同

name:可选参数,操作的名称

 

返回:

类型与 input 相同的张量

 

三、实例

data:2 行 3 列矩阵

tiled_data:按照 multiples 中对行重复 2 次,对列重复 3 次,因此就是 4 行 9 列数据

>>> import tensorflow as tf

>>> data = tf.constant(value=[[1,2,3],[4,5,6]])
>>> data
<tf.Tensor 'Const_4:0' shape=(2, 3) dtype=int32>

>>> tiled_data = tf.tile(input=data, multiples=[2,3])
>>> tiled_data
<tf.Tensor 'Tile_3:0' shape=(4, 9) dtype=int32>

>>> sess = tf.InteractiveSession()

>>> print(sess.run(fetches=[data, tiled_data]))
[array([[1, 2, 3],
       [4, 5, 6]]), array([[1, 2, 3, 1, 2, 3, 1, 2, 3],
       [4, 5, 6, 4, 5, 6, 4, 5, 6],
       [1, 2, 3, 1, 2, 3, 1, 2, 3],
       [4, 5, 6, 4, 5, 6, 4, 5, 6]])]

>>> sess.close()

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

csdn-WJW

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值