【发布时间】:2018-02-17 04:12:24
【问题描述】:
我有R 作为形状(N,2,2) 的二维旋转矩阵。现在我希望将每个矩阵扩展到(3,3) 3D 旋转矩阵,即在每个[:,:2,:2] 中放入零并将1 放入[:,2,2]。
如何在张量流中做到这一点?
更新
我试过这种方式
R = tf.get_variable(name='R', shape=np.shape(R_value), dtype=tf.float64,
initializer=tf.constant_initializer(R_value))
eye = tf.eye(np.shape(R_value)[1]+1)
right_column = eye[:2,2]
bottom_row = eye[2,:]
R = tf.concat([R, right_column], 3)
R = tf.concat([R, bottom_row], 2)
但是失败了,因为concat 不做广播...
更新 2
我在concat 调用中进行了显式广播并修复了错误的索引:
R = tf.get_variable(name='R', shape=np.shape(R_value), dtype=tf.float64,
initializer=tf.constant_initializer(R_value))
eye = tf.eye(np.shape(R_value)[1]+1, dtype=tf.float64)
right_column = eye[:2,2]
right_column = tf.expand_dims(right_column, 0)
right_column = tf.expand_dims(right_column, 2)
right_column = tf.tile(right_column, (np.shape(R_value)[0], 1, 1))
bottom_row = eye[2,:]
bottom_row = tf.expand_dims(bottom_row, 0)
bottom_row = tf.expand_dims(bottom_row, 0)
bottom_row = tf.tile(bottom_row, (np.shape(R_value)[0], 1, 1))
R = tf.concat([R, right_column], 2)
R = tf.concat([R, bottom_row], 1)
解决方案看起来相当复杂。有没有更简单的?
【问题讨论】:
标签: python indexing tensorflow padding rotational-matrices