繁体   English   中英

如何使用 tensorflow 对张量相位进行切片

[英]How to use tensorflow to slice a Tensor phase

如何使用 tensorflow 对张量相位进行切片:

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]]
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]
tensor =tf.constant([[6,2,3,4,5],[1,7,3,4,5],[1,2,3,4,5] ] )

new_tensor = tf.slice(tensor,[0,0],[-1,3])
print(new_tensor)

这输出

tf.Tensor(
[[6 2 3]
 [1 7 3]
 [1 2 3]], shape=(3, 3), dtype=int32)

    import tensorflow as tf
    sess=tf.Session()
    def sess_print(tensor):
        print(sess.run(tensor))
    
    tensor = tf.constant([[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5] ] )
    sess_print(tf.slice(tensor,[0,0],[3,3]))

[[1 2 3]
 [1 2 3]
 [1 2 3]]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM