我想使用qmath,一个四元数的库。qmath很奇怪AttributeError
这
from qmath import qmathcore
a = qmathcore.quaternion([1,2,3,4])
print a.conj()
给了我这样的回溯
Traceback (most recent call last):
File "*******/q_test.py", line 25, in <module>
print str(a.conj())
File "*******/venv/lib/python2.7/site-packages/qmath/qmathcore.py", line 788, in conj
return self.real() - self.imag()
File "*******/venv/lib/python2.7/site-packages/qmath/qmathcore.py", line 762, in imag
return self - self.real()
File "*******/venv/lib/python2.7/site-packages/qmath/qmathcore.py", line 522, in __sub__
self -= other
File "*******/venv/lib/python2.7/site-packages/qmath/qmathcore.py", line 407, in __isub__
self.other = quaternion(other)
File "*******/venv/lib/python2.7/site-packages/qmath/qmathcore.py", line 81, in __init__
self.q = q.q
AttributeError: quaternion instance has no attribute 'q'
但在文档他们说,这必须工作:
def conj(self):
"""
Returns the conjugate of the quaternion
>>> import qmathcore
>>> a = qmathcore.quaternion([1,2,3,4])
>>> a.conj()
(1.0-2.0i-3.0j-4.0k)
>>> a = qmathcore.hurwitz([1,2,3,4])
>>> a.conj()
(1-2i-3j-4k)
"""
return self.real() - self.imag()
这是什么?
顺便说一句,有没有人知道一个很好的四元数python库?我已经尝试过'qmath'(见问题),'Quaternion'(不能用非标准化的Qs)和'euclid',它在依赖关系中有很重的scipy,但不能乘以Qs和vector,而'quaternionarray'甚至没有进口。这真是难过;这真是伤心。 – akaRem
这个'qmath.quaternion(np.float64(1))'产生相同的错误。 'qmath.quaternion(np.float(1))'工作正常。我怀疑'qmath'写了2年后'numpy'的变化。 – hpaulj