返回在索引 axis 處插入長度為 1 的軸的張量。 (不推薦使用的參數)
用法
tf.compat.v1.expand_dims(
input, axis=None, name=None, dim=None
)參數
-
input一個Tensor。 -
axis0-D(標量)。指定展開input形狀的維度索引。必須在[-rank(input) - 1, rank(input)]範圍內。 -
name輸出的名稱Tensor(可選)。 -
dim0-D(標量)。等效於axis,將被棄用。
返回
-
與
input具有相同數據的Tensor,但其形狀添加了大小為 1 的附加維度。
拋出
-
ValueError如果指定了dim和axis中的任何一個或都沒有指定。
警告:不推薦使用某些參數:(dim)。它們將在未來的版本中被刪除。更新說明:改用 axis 參數
給定一個張量 input ,此操作在 input 的形狀的維度索引 axis 處插入一個長度為 1 的維度。維度索引遵循 Python 索引規則:它是從零開始的,一個負數索引它從末尾向後計數。
此操作可用於:
- 將外部"batch" 維度添加到單個元素。
- 對齊軸以進行廣播。
- 將內部向量長度軸添加到標量張量。
例如:
如果您有一個形狀為 [height, width, channels] 的圖像:
image = tf.zeros([10,10,3])
您可以通過傳遞 axis=0 添加外部 batch 軸:
tf.expand_dims(image, axis=0).shape.as_list()
[1, 10, 10, 3]
新軸位置與 Python list.insert(axis, 1) 匹配:
tf.expand_dims(image, axis=1).shape.as_list()
[10, 1, 10, 3]
遵循標準 Python 索引規則,負數 axis 從末尾開始計數,因此 axis=-1 添加了最內層維度:
tf.expand_dims(image, -1).shape.as_list()
[10, 10, 3, 1]
此操作要求 axis 是 input.shape 的有效索引,遵循 Python 索引規則:
-1-tf.rank(input) <= axis <= tf.rank(input)
此操作與以下內容有關:
tf.squeeze,刪除大小為 1 的維度。tf.reshape,提供更靈活的整形能力。tf.sparse.expand_dims,為tf.SparseTensor提供此函數
相關用法
- Python tf.compat.v1.executing_eagerly_outside_functions用法及代碼示例
- Python tf.compat.v1.executing_eagerly用法及代碼示例
- Python tf.compat.v1.estimator.DNNEstimator用法及代碼示例
- Python tf.compat.v1.estimator.experimental.KMeans用法及代碼示例
- Python tf.compat.v1.estimator.tpu.RunConfig用法及代碼示例
- Python tf.compat.v1.enable_eager_execution用法及代碼示例
- Python tf.compat.v1.estimator.regressor_parse_example_spec用法及代碼示例
- Python tf.compat.v1.estimator.BaselineRegressor用法及代碼示例
- Python tf.compat.v1.estimator.inputs.numpy_input_fn用法及代碼示例
- Python tf.compat.v1.estimator.LinearRegressor用法及代碼示例
- Python tf.compat.v1.enable_v2_tensorshape用法及代碼示例
- Python tf.compat.v1.estimator.BaselineEstimator用法及代碼示例
- Python tf.compat.v1.estimator.BaselineClassifier用法及代碼示例
- Python tf.compat.v1.estimator.LinearClassifier用法及代碼示例
- Python tf.compat.v1.estimator.DNNLinearCombinedRegressor用法及代碼示例
- Python tf.compat.v1.estimator.tpu.TPUEstimator用法及代碼示例
- Python tf.compat.v1.estimator.DNNClassifier用法及代碼示例
- Python tf.compat.v1.estimator.DNNRegressor用法及代碼示例
- Python tf.compat.v1.estimator.tpu.experimental.EmbeddingConfigSpec用法及代碼示例
- Python tf.compat.v1.estimator.DNNLinearCombinedEstimator用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.compat.v1.expand_dims。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
