我正在尝试实现一个函数 myGramSchmidt(L),它采用存在于某个内积空间中的向量列表 L,并返回一个已实现上述 Gram-Schmidt 过程的新列表。
我的代码:
def myGramSchmidt(L):
n = len(L)
V = L.copy()
for j in range(n):
V[j]= V[j].norm() #normalised vector
for i in range(j):
V[j] -= ip(V[i],V[j]) * V[i] #find value of V[j] which is orthogonal to every previous vectors
return V
我有错误
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-69-b1221e18fe68> in <module>()
14
15 if M.det() != Integer(0):
---> 16 GSL = myGramSchmidt(L)
17 GSM = Matrix(Integer(6),Integer(6),GSL)
18 assert len(GSL)==Integer(6)
<ipython-input-68-a8904262801b> in myGramSchmidt(L)
8 V[j]= V[j].norm() #normalised vector
9 for i in range(j):
---> 10 V[j] -= ip(V[i],V[j]) * V[i] #find value of V[j] which is orthogonal to every previous vectors
11 print(ip(V[Integer(1)],V[Integer(0)]))
12 print(ip(V[Integer(1)],V[Integer(2)]))
<ipython-input-4-f47230187e38> in ip(v, w)
6 #to save us some typing...
7 def ip(v,w):
----> 8 return v.inner_product(w)
9 def length(v):
10 return sqrt(ip(v,v))
/home/sage/sage/local/lib/python3.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.__getattr__ (build/cythonized/sage/structure/element.c:4614)()
485 AttributeError: 'LeftZeroSemigroup_with_category.element_class' object has no attribute 'blah_blah'
486 """
--> 487 return self.getattr_from_category(name)
488
489 cdef getattr_from_category(self, name):
/home/sage/sage/local/lib/python3.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.getattr_from_category (build/cythonized/sage/structure/element.c:4723)()
498 else:
499 cls = P._abstract_element_class
--> 500 return getattr_from_other_class(self, cls, name)
501
502 def __dir__(self):
/home/sage/sage/local/lib/python3.7/site-packages/sage/cpython/getattr.pyx in sage.cpython.getattr.getattr_from_other_class (build/cythonized/sage/cpython/getattr.c:2614)()
392 dummy_error_message.cls = type(self)
393 dummy_error_message.name = name
--> 394 raise AttributeError(dummy_error_message)
395 attribute = <object>attr
396 # Check for a descriptor (__get__ in Python)
AttributeError: 'sage.rings.rational.Rational' object has no attribute 'inner_product'
有人可以指出哪里出了问题吗?