[numarray] mean vector of 2d matrix

B

beliavsky

Curzio Basso said:
Hi all,

I was wondering what is the best way to compute the mean vector of a
matrix. Currently I'm doing this:

With Numeric, one can use the 'average' function to compute the average along
an axis, or the average of all elements when the axis argument is set to None.
See p317 of Martelli's "Python in a Nutshell" book. For example, the code

from Numeric import zeros,Float,average
nr = 3
nc = 2
xx = zeros([nr,nc],Float)
for i in range(nr):
for j in range(nc):
xx[i,j] = i + 10.0*j
print xx
for i in [None,0,1]: print "\n",i,average(xx,axis=i)

produces output

[[ 0. 10.]
[ 1. 11.]
[ 2. 12.]]

None 6.0

0 [ 1. 11.]

1 [ 5. 6. 7.]
 
C

Curzio Basso

With Numeric, one can use the 'average' function to compute the average along
an axis, or the average of all elements when the axis argument is set to None.
See p317 of Martelli's "Python in a Nutshell" book. For example, the code

However, it looks like in numarray no average() is provided. Now I found
out there is an average() function provided by the MA (Masked Arrays)
module, but I do not really understand why there is an average()
function for a masked array and not for a generic array...

Anyway, thanks for the tip!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top