Ask Your Question
0

summation of matrices

asked 2017-11-17 12:15:03 +0100

Deepak Sarma gravatar image

Can we use sum function to add a number of matrices? If not, then how to add a number of matrices with just a single command. Suppose I want to create 10 random matrices of order 5x5 and then want their sum as a result. I tried the following command, but it didn't work.

A_{i}=random_matrix(ZZ,5,5) for i in range(1,10); sum(A_{i}, i, 1, 10)

Note: I even could not generate 10 random matrices with the above command.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2017-11-17 12:54:06 +0100

tmonteil gravatar image

The following works:

sage: L = [random_matrix(ZZ,5,5) for i in range(1,10)] ; L
sage: sum(L)

or directly without creating a list first:

sage: sum(random_matrix(ZZ,5,5) for i in range(1,10))
edit flag offensive delete link more

Comments

Thank you.

Deepak Sarma gravatar imageDeepak Sarma ( 2017-11-17 14:04:44 +0100 )edit
0

answered 2017-11-18 06:19:36 +0100

Deepak Sarma gravatar image

L=[random_matrix(ZZ,5,5) for _ in range(1,10)]; sum(L[i] for i in range (0,9))

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-11-17 12:15:03 +0100

Seen: 1,049 times

Last updated: Nov 18 '17