将4D阵列转换为2D阵列,然后再次返回4D

时间:2019-09-06 14:39:21

标签: python arrays numpy multidimensional-array

在保存为4D numpy数组的视频中,我具有人的姿势(如左肘,右膝盖等关节的X,Y,Z值)。

示例:姿势保存在形状为3、103、25、2的数组中,表示: 3(坐标数),103(帧数),25(关节数),2(人数)。

现在,我想更改此观察的视角。即我要在所有关节位置值上应用旋转矩阵。

到目前为止,我是

  1. 重复人数
  2. 将每个人转换为二维数组
  3. 将2D数组与3x3旋转矩阵相乘
  4. 将旋转的2D数组重塑为3D数组
  5. 附加3D阵列
seq = np.random.rand(3, 103, 25, 2)
rot_mat = np.random.rand(3,3)
rotated_seq = np.zeros(seq.shape)
for i in range(seq.shape[3]):  # iterating through person
    person = seq[:, :, :, i]
    joint_values = np.reshape(person, (3, -1))
    rotated_joint_values = np.dot(joint_values.T, rot_mat).T
    rotated_person = np.reshape(rotated_joint_values, person.shape)
    rotated_seq[:, :, :, i] = rotated_person

我的问题是不使用for循环就可以执行任何操作。

0 个答案:

没有答案