我正在嘗試從input
獲取expected_out
。張量切片操作中的問題
input = [[2],[3],[3]]
expected_out = [2,3,3]
如何從input
使用TensorFlow得到expected_out
。
我正在嘗試從input
獲取expected_out
。張量切片操作中的問題
input = [[2],[3],[3]]
expected_out = [2,3,3]
如何從input
使用TensorFlow得到expected_out
。
在這種情況下,你想從基質中去除一維的條目。在TensorFlow和Numpy中,這個操作都被稱爲squeeze
。
這是TensorFlow的官方文檔 - tf.squeeze
。從文檔引用,
給定張量輸入,此操作返回的相同類型的去除了尺寸1的所有尺寸的張量。如果你不想刪除所有尺寸1個維,您可以通過指定軸
因此去除特定尺寸1種尺寸解決您的問題,您可以通過None
到axis
,默認情況下,或通過1
。下面是代碼的樣子,
expected_out = tf.squeeze(input)
,或者
expected_out = tf.squeeze(input, 1)
使用tf.squeeze:
import tensorflow as tf
input = tf.constant([[2], [3], [3]])
with tf.Session() as sess:
print(sess.run(tf.squeeze(input)))
做任何的答案能幫你嗎? – martianwars
是的。抱歉遲到。 – user4654