我想使用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