[英]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.