0
我有一个涉及到张量的一些整形一些张量流代码:Tensorflow:get_shape()在重塑()使用
# sigma has shape (15000,20,2)
sigma_shape = sigma.get_shape()
# We want to reshape it to (300000,2)
sigma = tf.reshape(sigma, [-1, sigma_shape[-1]]) # (300000,2)
# Because we have to do this operation
Sigma = matrix_with_upper_values(rho) + tf.matrix_diag(tf.square(sigma))
# Reshape back, Sigma is (300000,2,2), we want it to be (15000,20,2,2)
Sigma = tf.reshape(Sigma, sigma_shape.append(sigma_shape[-1]))
这就是我想要做的事。但是:
sigma_shape
是张量形对象和sigma_shape[2]
其不能在tf.reshape在这种方式中使用的Dimension(2)
。sigma_shape
.append(sigma_shape[-1]
)这也行不通。有没有另一种方法来做到这一点?