TensorFlow是Google設計的開源Python庫,用於開發機器學習模型和深度學習神經網絡。
dynamic_stitch()用於將多個張量合並為單個張量。
用法:tensorflow.dynamic_stitch( indices, data, name)
參數:
- indices:它是具有至少1個張量且每個張量具有dtype int32的張量的列表。
- 數據:它是具有與索引相同長度的張量的列表。
- 名稱(可選):它定義了操作的名稱。
結果:
它返回與數據相同dtype的張量。
範例1:
Python3
# Importing the library
import tensorflow as tf
# Initializing the input
indices = [[0, 1, 5], [2, 4, 3, 6]]
data = [[1, 2, 3], [4, 5, 6, 7]]
# Printing the input
print('indices:', indices)
print('data:', data)
# Calculating result
x = tf.dynamic_stitch(indices, data)
# Printing the result
print('x:', x)
輸出:
indices:[[0, 1, 5], [2, 4, 3, 6]] data: [[1, 2, 3], [4, 5, 6, 7]] x: tf.Tensor([1 2 4 6 5 3 7], shape=(7, ), dtype=int32)
範例2:
Python3
# Importing the library
import tensorflow as tf
# Initializing the input
indices = [[0, 1, 6], [5, 4, 3]]
data = [[1, 2, 3], [4, 5, 6]]
# Printing the input
print('indices:', indices)
print('data:', data)
# Calculating result
x = tf.dynamic_stitch(indices, data)
# Printing the result
print('x:', x)
輸出:
indices:[[0, 1, 2], [5, 4, 3]] data: [[1, 2, 3], [4, 5, 6]] x: tf.Tensor([1 2 3 6 5 4], shape=(6, ), dtype=int32)
相關用法
注:本文由純淨天空篩選整理自aman neekhara大神的英文原創作品 Python – tensorflow.dynamic_stitch()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。