擅长:python、mysql、java
<p>挤压移除大小为“1”的变形。下面的示例将显示挤压的用法。</p>
<pre><code>import tensorflow as tf
tf.enable_eager_execution() ##if using TF1.4 for TF2.0 eager mode is the default mode.
####example 1
a = tf.constant(value=[1,3,4,5],shape=(1,4))
print(a)
Output : tf.Tensor([[1 3 4 5]], shape=(1, 4), dtype=int32)
#after applying tf.squeeze shape has been changed from (4,1) to (4, )
b = tf.squeeze(input=a)
print(b)
output: tf.Tensor([1 3 4 5], shape=(4,), dtype=int32)
####example2
a = tf.constant(value=[1,3,4,5,4,6], shape=(3,1,2))
print(a)
Output:tf.Tensor(
[[[1 3]]
[[4 5]]
[[4 6]]], shape=(3, 1, 2), dtype=int32)
#after applying tf.squeeze shape has been chnaged from (3, 1, 2) to (3, 2)
b = tf.squeeze(input=a)
print(b)
Output:tf.Tensor(
[[1 3]
[4 5]
[4 6]], shape=(3, 2), dtype=int32)
</code></pre>