簡體   English   中英

Tensorflow Concat 2D尺寸張量到3D尺寸張量

[英]Tensorflow concat 2D dimension Tensor to a 3D dimension tensor

這是一個簡單的問題。 我有一個3D形狀的張量。 可以說是[2,2,3] 我還有一個2D形狀的張量[2,2] 但是這兩個元素的前兩個維度是匹配的。 我想對它們進行concat ,以便將2D張量添加到三維的3D張量中。 [2,2,4]

我不確定如何實現這一目標。 我嘗試使用tf.concattf.stack但這需要兩個張量都處於同一等級。

您可以使用tf.expand_dims()將較小的張量轉換為正確的秩,然后使用tf.concat()

tensor_3d = tf.placeholder(tf.float32, shape=[2, 2, 3])
tensor_2d = tf.placeholder(tf.float32, shape=[2, 2])

tensor_2d_as_3d = tf.expand_dims(tensor_2d, 2)  # shape: [2, 2, 1]

result = tf.concat([tensor_3d, tensor_2d_as_3d], 2)  # shape: [2, 2, 4]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM