Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Need only the final result of for loop

Suppose I want to increase each off diagonal element of a matrix by 1. Myy program gives me a sequence of matrices each time changing only one entry. I just need the final matrix of the sequence. Please check the following program. What modification is required so that the program changes all the entries at a time?

A=random_matrix(QQ,5,5) B=copy(A) for i in range(A.nrows()): for j in range(A.nrows()): if i!=j: B[i,j]=A[i,j]+1 print A,B

Need only the final result of for loop

Suppose I want to increase each off diagonal element of a matrix by 1. Myy program gives me a sequence of matrices each time changing only one entry. I just need the final matrix of the sequence. Please check the following program. What modification is required so that the program changes all the entries at a time?

A=random_matrix(QQ,5,5)
B=copy(A)
for i in range(A.nrows()):
    for j in range(A.nrows()):
        if i!=j:
            B[i,j]=A[i,j]+1
            print A,B

A,B