tf.squeeze Sample Code

Official website has introduced this method, but the lack of validation example, while the Baidu search to the translation from the official line are over, right down are correct, but the lack of validation example, here to write a sample code, hoping to help understanding

import tensorflow as tf

k = tf.constant([[[[[[1]],[[2]],[[3]]]],[[[[4]],[[5]],[[6]]]]]])

with tf.Session() as sess:
	print(sess.run(tf.shape(k)))
	print("-----------------------")
	print(sess.run(tf.squeeze(k)))

Run results

[1 2 1 3 1 1]
-----------------------
[[1. 2. 3.]
 [4. 5. 6.]]
 

Roughly meaning get rid of a lot of square brackets, (* ^ ▽ ^ *)

Guess you like

Origin blog.csdn.net/zhqh100/article/details/88692817