將維度 1 插入到張量的形狀中。
用法
tf.raw_ops.ExpandDims(
input, axis, name=None
)參數
-
input一個Tensor。 -
axis一個Tensor。必須是以下類型之一:int32,int64。 0-D(標量)。指定擴展input形狀的維度索引。必須在[-rank(input) - 1, rank(input)]範圍內。 -
name操作的名稱(可選)。
返回
-
一個
Tensor。具有與input相同的類型。
給定一個張量 input ,此操作在 input 的形狀的維度索引 axis 處插入維度 1。維度索引axis 從零開始;如果您為 axis 指定負數,則它從末尾倒數。
如果您想將批量維度添加到單個元素,此操作很有用。例如,如果您有一個形狀為 [height, width,
channels] 的圖像,則可以使用 expand_dims(image, 0) 將其製作為一組 1 張圖像,這將生成形狀為 [1, height, width, channels] 。
其他示例:
# 't' is a tensor of shape [2]
shape(expand_dims(t, 0)) ==> [1, 2]
shape(expand_dims(t, 1)) ==> [2, 1]
shape(expand_dims(t, -1)) ==> [2, 1]
# 't2' is a tensor of shape [2, 3, 5]
shape(expand_dims(t2, 0)) ==> [1, 2, 3, 5]
shape(expand_dims(t2, 2)) ==> [2, 3, 1, 5]
shape(expand_dims(t2, 3)) ==> [2, 3, 5, 1]
此操作要求:
-1-input.dims() <= dim <= input.dims()
此操作與 squeeze() 相關,它刪除大小為 1 的維度。
相關用法
- Python tf.raw_ops.Expm1用法及代碼示例
- Python tf.raw_ops.Exp用法及代碼示例
- Python tf.raw_ops.ExtractVolumePatches用法及代碼示例
- Python tf.raw_ops.Erf用法及代碼示例
- Python tf.raw_ops.Elu用法及代碼示例
- Python tf.raw_ops.Equal用法及代碼示例
- Python tf.raw_ops.Eig用法及代碼示例
- Python tf.raw_ops.TPUReplicatedInput用法及代碼示例
- Python tf.raw_ops.Bitcast用法及代碼示例
- Python tf.raw_ops.SelfAdjointEigV2用法及代碼示例
- Python tf.raw_ops.BatchMatMul用法及代碼示例
- Python tf.raw_ops.OneHot用法及代碼示例
- Python tf.raw_ops.ResourceScatterNdSub用法及代碼示例
- Python tf.raw_ops.ReadVariableXlaSplitND用法及代碼示例
- Python tf.raw_ops.GatherV2用法及代碼示例
- Python tf.raw_ops.BitwiseAnd用法及代碼示例
- Python tf.raw_ops.UniqueWithCounts用法及代碼示例
- Python tf.raw_ops.DecodeGif用法及代碼示例
- Python tf.raw_ops.Size用法及代碼示例
- Python tf.raw_ops.ScatterUpdate用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.raw_ops.ExpandDims。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
