tf.expand_dims()函数的用法
expand_dims():
顾名思义,即扩展维数。
函数:
expand_dims(input, axis=None, name=None, dim=None)
作用:
在指定轴为输入数据增加一维
参数:
常用到参数只有两个,即input和axis
input: 即输入张量
axis:指定在哪一维为输入张量添加维数
实例:
# 't' is a tensor of shape [2]
tf.shape(tf.expand_dims(t, 0)) # [1, 2]
tf.shape(tf.expand_dims(t, 1)) # [2, 1]
tf.shape(tf.expand_dims(t, -1)) # [2, 1]
# 't2' is a tensor of shape [2, 3, 5]
tf.shape(tf.expand_dims(t2, 0)) # [1, 2, 3, 5]
tf.shape(tf.expand_dims(t2, 2)) # [2, 3, 1, 5]
tf.shape(tf.expand_dims(t2, 3)) # [2, 3, 5, 1]