我有 2 張量,如:
a = tf.constant([[1, 2, 3], [1, 2, 3]])
b = tf.constant([1, 2, 3, 4, 5])
我想要的輸出是:
<tf.Tensor: shape=(4, 2), dtype=int64, numpy=
array([[1, 2, 3, 0, 0],
[1, 2, 3, 0, 0],
[1, 2, 3, 4, 5]], dtype=int64)>
但是當我嘗試時出現tf.concat([a, b], axis=0)此錯誤:
InvalidArgumentError: ConcatOp : Dimensions of inputs should match: shape[0] = [2,3] vs. shape[1] = [1,5] [Op:ConcatV2] name: concat
uj5u.com熱心網友回復:
嘗試這個:
a = tf.constant([[1, 2, 3], [1, 2, 3]])
b = tf.constant([1, 2, 3, 4, 5])
c = tf.concat([tf.pad(a, tf.constant([[0,0], [0,2]])), tf.expand_dims(b, axis=0)], axis=0)
tf.print(c)
[[1 2 3 0 0]
[1 2 3 0 0]
[1 2 3 4 5]]
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/375443.html
