tf.strided_slice 实例

tf.stride_slice(data, begin, end)
tf.slice(data, begin, end)
和tf.slice的区别是slice的end索引是闭区间,stride_slice的end索引是开区间,所以一个截掉最后一列(remove the last element or column of each line)的小技巧是用stride_slice(data, [0, 0], [rows, -1]),但是如果是用slice(data, [0, 0], [rows, -1])则仍是原矩阵。

import tensorflow as tf
data = [1,2,3,4,5,6,7,8]
x = tf.strided_slice(data,[0],[4])
y = tf.strided_slice(data,[1],[5])
with tf.Session() as sess:
    print(sess.run(x))
    print(sess.run(y))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

结果
[1 2 3 4]
[2 3 4 5]

import tensorflow as tf
data = [[1,2,3,4,5,6,7,8],[11,12,13,14,15,16,17,18]]
x = tf.strided_slice(data,[0,0],[1,4])
y = tf.strided_slice(data,[1,1],[2,5])
with tf.Session() as sess:
    print(sess.run(x))
    print(sess.run(y))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

结果
[[1 2 3 4]]
[[12 13 14 15]]


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值