John Lawrence Aspden
John Lawrence Aspden

Reputation: 17470

In Maxima how do I get the row sums of a matrix?

e.g. matrix:

a b c 
d e f 
g h i

->

column vector

a+b+c
d+e+f
g+h+i

I can think of ugly solutions with sum, and maybe less ugly solutions with multiplying by a row vector, but is there a nice way?

Upvotes: 1

Views: 623

Answers (1)

Robert Dodier
Robert Dodier

Reputation: 17576

A matrix is represented as a wrapper around a collection of lists, where each list is a row. So mapping over the arguments of matrix is mapping over the rows. You can do something like this: map(lambda([r], [lsum(x, x, r)]), A) where A is your matrix.

Upvotes: 3

Related Questions