Ask Your Question
0

Naming variables in a loop [closed]

asked 2015-12-23 14:27:45 +0200

bruno171092 gravatar image

I have this problem: Lets say i have an matrix A and use A.gram_schmidt() on it. then i get a matrix B whose rows are orthogonal. So what do i do now if i want use the vectors of the rows. How can i make them to variables practical? I tried this:

O, t = A.gram_schmidt() 
for i in range(n):
    wi = O.row(i)

But clearly this doesnt work, because sage doesnt identiy the "i" in "wi"...

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by bruno171092
close date 2015-12-23 16:20:25.216696

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-12-23 15:33:28 +0200

vdelecroix gravatar image

updated 2015-12-23 15:40:08 +0200

It is not of very good practice to use variable names that depend on indices. And in practice this is hard to manipulate. You can alternatively do

sage: O, t =  A.gram_schmidt()
sage: w = O.rows()
sage: w[0]
-> the first row
sage: w[1]
-> the second row

But since you have the function O.row available I do not see why you need to make variables out of it.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-12-23 14:27:45 +0200

Seen: 202 times

Last updated: Dec 23 '15