Python pyquaternion:ValueError:序列中的元素数意外

Python pyquaternion:ValueError:序列中的元素数意外,python,numpy,rotation,quaternions,valueerror,Python,Numpy,Rotation,Quaternions,Valueerror,使用,我想获得3x3旋转矩阵的四元数表示。执行时,它返回ValueError:序列中意外的元素数。得到:3,预期:4。。根据文档,用3x3矩阵实例化四元数应该可以,或者我可能误解了什么 为了测试这一点,我找到了随机旋转矩阵生成的方法。如上所述,我只收到此错误消息 import numpy as np from pyquaternion import Quaternion def rand_rotation_matrix(deflection=1.0, randnums=None): "

使用,我想获得3x3旋转矩阵的四元数表示。执行时,它返回ValueError:序列中意外的元素数。得到:3,预期:4。。根据文档,用3x3矩阵实例化四元数应该可以,或者我可能误解了什么

为了测试这一点,我找到了随机旋转矩阵生成的方法。如上所述,我只收到此错误消息

import numpy as np
from pyquaternion import Quaternion

def rand_rotation_matrix(deflection=1.0, randnums=None):
    """
    Creates a random rotation matrix.

    deflection: the magnitude of the rotation. For 0, no rotation; for 1, competely random
    rotation. Small deflection => small perturbation.
    randnums: 3 random numbers in the range [0, 1]. If `None`, they will be auto-generated.
    """
    # from http://www.realtimerendering.com/resources/GraphicsGems/gemsiii/rand_rotation.c

    if randnums is None:
        randnums = np.random.uniform(size=(3,))

    theta, phi, z = randnums

    theta = theta * 2.0*deflection*np.pi  # Rotation about the pole (Z).
    phi = phi * 2.0*np.pi  # For direction of pole deflection.
    z = z * 2.0*deflection  # For magnitude of pole deflection.

    # Compute a vector V used for distributing points over the sphere
    # via the reflection I - V Transpose(V).  This formulation of V
    # will guarantee that if x[1] and x[2] are uniformly distributed,
    # the reflected points will be uniform on the sphere.  Note that V
    # has length sqrt(2) to eliminate the 2 in the Householder matrix.

    r = np.sqrt(z)
    Vx, Vy, Vz = V = (
        np.sin(phi) * r,
        np.cos(phi) * r,
        np.sqrt(2.0 - z)
        )

    st = np.sin(theta)
    ct = np.cos(theta)

    R = np.array(((ct, st, 0), (-st, ct, 0), (0, 0, 1)))

    # Construct the rotation matrix  ( V Transpose(V) - I ) R.

    M = (np.outer(V, V) - np.eye(3)).dot(R)
    return M

rotation1 = rand_rotation_matrix()
rotation2 = rand_rotation_matrix()

print(Quaternion(rotation1.dot(rotation2.T)))
根据文档中向下滚动的部分,要从旋转矩阵初始化,必须使用矩阵=关键字参数,例如四元数矩阵=R