假設我有三個具有形狀的 numpy 陣列,(1,3)并將它們堆疊成具有形狀(2,3)和(1,3). 然后我把它們疊加起來tf.ragged.stack得到一個參差不齊的張量:
x1 = np.asarray([1,0,0])
x2 = np.asarray([0,1,0])
x3 = np.asarray([0,0,1])
group_a = np.stack([x1,x2])
group_b = np.stack([x3])
ac = tf.ragged.stack([group_a,group_b], axis=0)
我希望它的形狀是,(2, None, 3)但它是(2, None, None). 我如何獲得所需的形狀?我正在使用張量流 2.5.2
uj5u.com熱心網友回復:
發生這種情況是因為tf.ragged.stack正在創建一個等于 2 的 ragged_rank。查看檔案以獲取更多資訊。您可以像這樣明確定義如何對參差不齊的張量進行磁區:
import tensorflow as tf
import numpy as np
x1 = np.asarray([1,0,0])
x2 = np.asarray([0,1,0])
x3 = np.asarray([0,0,1])
ac = tf.RaggedTensor.from_row_splits(
values=[x1, x2, x3],
row_splits=[0, 2, 3])
print(ac.shape)
print(ac)
(2, None, 3)
<tf.RaggedTensor [[[1, 0, 0], [0, 1, 0]], [[0, 0, 1]]]>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/402829.html
標籤:
