Ask Your Question

# summation of matrices 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 close merge delete

## 2 answers

Sort by » oldest newest most voted

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))

more

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

more

## Your Answer

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

Add Answer

## Stats

Asked: 2017-11-17 05:15:03 -0500

Seen: 259 times

Last updated: Nov 17 '17