循环遍历 sage 中矩阵的行
我正在尝试在 sage 中编写 Graham-Schmidt 进程,但无法弄清楚如何循环遍历数组的行。
def graham_schmidt(W):
a=0
U=W
for i in W.dims()[0]:# this is the not working part
print w
a=a+1
for j in xrange(0,-2):
a=a+1
U[i]=U[i]-(transpose(U[j])*w)/(transpose(U[j])*U[j])*U[j]
return a;
I am trying to program a Graham-Schmidt process in sage and cannot figure out how to loop through the rows of an array.
def graham_schmidt(W):
a=0
U=W
for i in W.dims()[0]:# this is the not working part
print w
a=a+1
for j in xrange(0,-2):
a=a+1
U[i]=U[i]-(transpose(U[j])*w)/(transpose(U[j])*U[j])*U[j]
return a;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你把事情搞得太复杂了。如果
W
不是稀疏矩阵,你可以这样做因为你还需要行索引,所以你可以使用 Python 的内置
enumerate
:或(丑陋)
You're making things far too complicated. If
W
is not a sparse matrix, you can just doSince you also need the row index, you can use Python's built-in
enumerate
:or (uglier)