First time here? Check out the FAQ!

Ask Your Question
0

summation of matrices

asked 7 years ago

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.

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
0

answered 7 years ago

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))
Preview: (hide)
link

Comments

Thank you.

Deepak Sarma gravatar imageDeepak Sarma ( 7 years ago )
0

answered 7 years ago

Deepak Sarma gravatar image

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

Preview: (hide)
link

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

Seen: 1,221 times

Last updated: Nov 18 '17