Deep learning和tensorflow学习记录(五):tf.expand_dims

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

定义于:tensorflow/python/ops/array_ops.py。

为Tensor的shape增加一个为1的维度。

给定一个Tensor input,在axis轴处给input增加一个为1的维度。例如:你的input的shape是[height, width, channels],执行expand_dims(image, 0)之后就变成[1, height, width, channels]。

参数:

axis:0-D(标量)。指定展开shape的尺寸索引input。必须在[-rank(input) - 1, rank(input)]。

name:输出名称。

dim:0-D(标量)。相当于aixs,待弃用。

返回:

A Tensor:和input具有相同的数据,但形状增加一个维度。

# '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]

猜你喜欢

转载自blog.csdn.net/heiheiya/article/details/80943390
今日推荐