thensorsflow 矩阵增加/降低一个维度
Posted George
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了thensorsflow 矩阵增加/降低一个维度相关的知识,希望对你有一定的参考价值。
import tensorflow as tf a = tf.constant([[1, 2],[2,4]]) b = tf.expand_dims(a,1) with tf.Session() as sess: a_, b_ = sess.run([a, b])
结果:
a: (2,2)
b:(2,1,2)
import tensorflow as tf a = tf.constant([[1, 2],[2,4]]) b = tf.expand_dims(a,0) with tf.Session() as sess: a_, b_ = sess.run([a, b])
结果:
a: (2,2)
b:(1,2,2)
import tensorflow as tf a = tf.constant([[1, 2],[2,4]]) b = tf.expand_dims(a,2) with tf.Session() as sess: a_, b_ = sess.run([a, b])
结果:
a: (2,2)
b:(2,2,1)
降低维度
import tensorflow as tf a = tf.constant([[1, 2, 3]]) b = tf.squeeze(a) with tf.Session() as sess: a_, b_ = sess.run([a, b])
结果:
a: (1,3)
b:(3,)
以上是关于thensorsflow 矩阵增加/降低一个维度的主要内容,如果未能解决你的问题,请参考以下文章