tf.expand_dims(input, axis=None, name=None, dim=None)
在axis的位置增加维度为1的维度。 给定张量input,此操作在input的形状的维度索引axis处插入1维。 维度索引axis从零开始,如果您指定轴的负数,则从最后向前计数。 如果要将批次尺寸添加到单个元素,此操作很有用。例如,如果您有一个shape的图像[height, width, channels],则可以用制作一批1张图像expand_dims(image, 0),这将使shape成为[1, height, width, channels]。
参数:
input张量
axis指定要扩展input形状的维度索引name输出张量的名称dim等效于axis,不推荐使用
返回: 一个张量,与input有相同的数据,但形状添加了维度为1的附加维度。
例子
>>>tf
.shape
(expand_dims
(t
, 0))
[1, 2]
>>>shape
(expand_dims
(t
, 1))
[2, 1]
>>>shape
(expand_dims
(t
, -1))
[2, 1]
错误 ValueError:同时指定dim和axis。