First time here? Check out the FAQ!

Ask Your Question
0

Naming variables in a loop [closed]

asked 9 years ago

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"...

Preview: (hide)

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 9 years ago

vdelecroix gravatar image

updated 9 years ago

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.

Preview: (hide)
link

Question Tools

1 follower

Stats

Asked: 9 years ago

Seen: 318 times

Last updated: Dec 23 '15