tensorflow | 维度转换

学习维度转换

shape 计算维度

tf.shape(input,name = None)

案例1

a = tf.constant([i for i in range(20)],shape =[2,2,5])
with tf.Session() as sess:
    print (sess.run(tf.shape(a)))

结果:[2 2 5]

size 计算元素个数

tf.size(input,name = None)

案例2

a = tf.constant([i for i in range(20)],shape =[2,2,5])
with tf.Session() as sess:
    print (sess.run(tf.size(a)))

结果:20

rank 计算秩

tf.rank(input, name=None)

案例3

a = tf.constant([i for i in range(20)],shape =[2,2,5])
with tf.Session() as sess:
    print (sess.run(tf.rank(a)))

结果 : 3

reshape重新的规则排列

tf.reshape(tensor, shape, name=None)

案例4

a = tf.constant([i for i in range(20)],shape =[2,2,5])
with tf.Session() as sess:
    print (sess.run(tf.reshape(a,shape = [5,2,2])))

原始的数据
这里写图片描述
结果:
这里写图片描述

squeeze

没理解,等理解了再来更新。

tf.squeeze(input, squeeze_dims=None, name=None)

expand_dims

没理解,等理解了再来更新。

tf.expand_dims(input, dim, name=None)

猜你喜欢

转载自blog.csdn.net/xxzhangx/article/details/78848041