码迷,mamicode.com
首页 > 其他好文 > 详细

thensorsflow 矩阵增加/降低一个维度

时间:2020-07-26 01:32:15      阅读:53      评论:0      收藏:0      [点我收藏+]

标签:squeeze   code   nbsp   pre   一个   str   div   on()   with   

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 矩阵增加/降低一个维度

标签:squeeze   code   nbsp   pre   一个   str   div   on()   with   

原文地址:https://www.cnblogs.com/ai-learning-blogs/p/13377954.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!