首页 > 解决方案 > 如何使用 tensorflow 对 Tensor 阶段进行切片

问题描述

如何使用 tensorflow 对 Tensor 阶段进行切片:

tensor = tf.constant([[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5] ] )
    list = [0,2]

我想得到结果张量:

result_tensor = [[1,2,3],[1,2,3],[1,2,3]]

标签: pythontensorflow

解决方案


tensor =tf.constant([[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5] ] )
lst = [0,2]
tensor[:, lst[0]:lst[1]+1]

推荐阅读