[SciPy-user] mean of recarray

Gabriel J.L. Beckers beckers at orn.mpg.de
Tue Mar 6 11:56:05 EST 2007


Is there an easy way to get the mean of a record array?

There is a mean() method, but it doesn't seem to work for me.

In [1]: import numpy

In [2]: desc = numpy.dtype({'names':['a','b'],'formats':['d','d']})

In [3]: ar = numpy.array([(1.,2.),(3.,4.)],dtype=desc)

In [4]: ar.mean()
---------------------------------------------------------------------------
exceptions.TypeError                                 Traceback (most
recent call last)

/home/user/<ipython console> 

TypeError: cannot perform reduce with flexible type

I would actually be able to get the mean along the second axis, like
ar.mean(1). Can this be done in a simple way?

Cheers, Gabriel









More information about the SciPy-User mailing list