將秩列表 - R 張量堆疊到一個秩 - (R+1) 張量中。
用法
tf.stack(
values, axis=0, name='stack'
)參數
-
values具有相同形狀和類型的Tensor對象列表。 -
axis一個int。要堆疊的軸。默認為第一個維度。負值環繞,因此有效範圍是[-(R+1), R+1)。 -
name此操作的名稱(可選)。
返回
-
output與values具有相同類型的堆疊Tensor。
拋出
-
ValueError如果axis超出範圍 [-(R+1), R+1)。
另見tf.concat、tf.tile、tf.repeat。
將 values 中的張量列表打包成一個比 values 中的每個張量高一級的張量,方法是將它們沿 axis 維度打包。給定形狀為 (A, B, C) 的張量的長度為 N 的列表;
如果 axis == 0 那麽 output 張量將具有形狀 (N, A, B, C) 。如果 axis == 1 那麽 output 張量將具有形狀 (A, N, B, C) 。等等。
例如:
x = tf.constant([1, 4])
y = tf.constant([2, 5])
z = tf.constant([3, 6])
tf.stack([x, y, z])
<tf.Tensor:shape=(3, 2), dtype=int32, numpy=
array([[1, 4],
[2, 5],
[3, 6]], dtype=int32)>
tf.stack([x, y, z], axis=1)
<tf.Tensor:shape=(2, 3), dtype=int32, numpy=
array([[1, 2, 3],
[4, 5, 6]], dtype=int32)>
這與 unstack 正好相反。 numpy 等價物是np.stack
np.array_equal(np.stack([x, y, z]), tf.stack([x, y, z]))
True
相關用法
- Python tf.strings.substr用法及代碼示例
- Python tf.strings.reduce_join用法及代碼示例
- Python tf.strings.regex_full_match用法及代碼示例
- Python tf.strings.regex_replace用法及代碼示例
- Python tf.strings.length用法及代碼示例
- Python tf.strided_slice用法及代碼示例
- Python tf.strings.bytes_split用法及代碼示例
- Python tf.strings.as_string用法及代碼示例
- Python tf.strings.unsorted_segment_join用法及代碼示例
- Python tf.stop_gradient用法及代碼示例
- Python tf.strings.lower用法及代碼示例
- Python tf.strings.split用法及代碼示例
- Python tf.strings.upper用法及代碼示例
- Python tf.strings.unicode_decode_with_offsets用法及代碼示例
- Python tf.strings.join用法及代碼示例
- Python tf.strings.to_hash_bucket用法及代碼示例
- Python tf.strings.ngrams用法及代碼示例
- Python tf.strings.to_hash_bucket_strong用法及代碼示例
- Python tf.strings.unicode_decode用法及代碼示例
- Python tf.strings.unicode_encode用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.stack。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
