Deep learning和tensorflow学习记录(八):tf.slice

tf.slice(
    input_,
    begin,
    size,
    name=None
)
 
 
定义于:tensorflow/python/ops/array_ops.py

从Tensor中提取一个slice。

此操作从一个input Tensor的指定位置begin开始提取一个大小为size的slice。slice的大小是size,size[i]是input第i个维度上要提取的元素的数量。begin表示input每个维度上的偏移量。

参数:

input_:A Tensor。

begin:A Tensor,类型为int32或int64。

size:A Tensor,类型为int32或int64。

name:操作的名称(可选)。

返回值:

A Tensor:和input_具有相同的类型。

t = tf.constant([[[1, 1, 1], [2, 2, 2]],
                 [[3, 3, 3], [4, 4, 4]],
                 [[5, 5, 5], [6, 6, 6]]])
tf.slice(t, [1, 0, 0], [1, 1, 3])  # [[[3, 3, 3]]]
tf.slice(t, [1, 0, 0], [1, 2, 3])  # [[[3, 3, 3],
                                   #   [4, 4, 4]]]
tf.slice(t, [1, 0, 0], [2, 1, 3])  # [[[3, 3, 3]],
                                   #  [[5, 5, 5]]]

猜你喜欢

转载自blog.csdn.net/heiheiya/article/details/80943941
今日推荐