我有一個矩陣M:張量流體張量操作 - 用尺寸對象平鋪不起作用?
[[101, 51, 12],
[101, 19, 18]]
長話短說,我需要創建tensorflow語法如下:
[[0, 0, 101],
[0, 1, 51],
[0, 2, 12],
[1, 0, 101],
[1, 1, 19],
[1, 2, 18]]
我的方法是創建3個單獨的載體和加入到其中來產生以上:
v1 = [0, 0, 0, 1, 1, 1]
v2 = [0, 1, 2, 0, 1, 2]
and
M_flat = [101, 51, 12, 101, 19, 18]
我可以用得到M_flat = [101, 51, 12, 101, 19, 18]
tf.reshape(M, shape=(-1,))
我不知道M的提前尺寸,所以我用下面的語法來獲得它:
dim0 = M.get_shape()[0]
dim1 = M.get_shape()[1]
從這個我可以通過
tf.range(dim1)
獲得[0, 1, 2]
要獲得[0, 1, 2, 0, 1, 2]
我試着平鋪:
tf.tile(tf.range(dim1), [dim0])
但是,這不起作用,因爲dim0
是尺寸對象,並且tile
想要一個整數,所以我得到的錯誤Expected binary or unicode string, got Dimension(100)
另外,我不知道如果tile
可以用來生產這種[0, 0, 0, 1, 1, 1]
(也許有些重塑,調換,和瓷磚雖然可以,再假設這些操作可以關閉的dim0
工作和dim1
而不是顯式數字)
有沒有更好的方法來做我想做的事情?
請你發表您的代碼複製此錯誤?人們只需要做一些改變就可以使其發揮作用。 – hars