我想在tensorflow中创建一个旋转矩阵,其中所有部分都是张量.
是)我有的:
def rotate(tf, points, theta):
rotation_matrix = [[tf.cos(theta), -tf.sin(theta)],
[tf.sin(theta), tf.cos(theta)]]
return tf.matmul(points, rotation_matrix)
Run Code Online (Sandbox Code Playgroud)
但是这表示这rotation_matrix是一个张量列表而不是张量本身. theta也是在运行时传入的张量对象.
有两个操作:
def rotate(tf, points, theta):
rotation_matrix = tf.pack([tf.cos(theta),
-tf.sin(theta),
tf.sin(theta),
tf.cos(theta)])
rotation_matrix = tf.reshape(rotation_matrix, (2,2))
return tf.matmul(points, rotation_matrix)
Run Code Online (Sandbox Code Playgroud)