Averaging all the rows in a matrix

Jun 25, 2009 at 1:00am

Averaging all the rows in a matrix

I would like to take a 2D matrix and get a vector out. Each element in the vector would be the average value of the corresponding column in the matrix. For a small example:

0 1 1
2 3 4
5 2 1

Would lead to:

7/3 2 2

It is relatively easy to do with jit.convolve and a kernel big enough to grab every value in a column, but that seems terribly inefficient. Is there a better way to do this?

#44531
Jun 25, 2009 at 3:00am

way back when, I wrote an object for exactly this purpose called xray.jit.mean:

http://mat.ucsb.edu/whsmith/xray/xray.jit.mean.html

wes

#160187
Jun 25, 2009 at 4:15am

Thank you, that is just what I needed!

#160188

You must be logged in to reply to this topic.