# [SciPy-user] array mean issue...

Jean-Pascal Mercier Jean-Pascal.Mercier@inrialpes...
Wed Jun 11 07:03:03 CDT 2008

```Hi Fred,

The problem is the container used to calculate the mean. The default
behavior is to use the same container as the passed array dtype. When
the array is really big, the float32 container simply become very
inefficient which account for the error you've encounter. This can be
easily solved by providing the dtype as a function parameter.

In [1]: from scipy import *

In [2]: a = rand(400,400,400)

In [3]: b = asarray(a, dtype=float32)

In [4]: a.mean()
Out[4]: 0.500014522905

In [6]: b.mean()
Out[6]: 0.262144

In [6]: b.mean(dtype=float64)
Out[6]: 0.500014522902

Cheers,

/J-Pascal MERCIER
Projet PRIMA - Laboratoire LIG
INRIA Grenoble Rhone-Alpes Research Centre
/

fred wrote:
> Hi,
>
> I get the following issue I don't understand:
>
> marsu:~/{1}/> a=rand(400,400,400)
>
> marsu:~/{2}/> a.mean()
> Out[2]: 0.500002086829
>
> marsu:~/{3}/> b=asarray(a, dtype='f')
>
> marsu:~/{4}/> b.mean()
> Out[4]: 0.262144
>
> What's going on ?
>
> How can I compute the mean on "big" float arrays ?
>
> By "big", I mean that for array of 300x300x300, I get the same results
> for float32 and float64 arrays.
>
> TIA.
>
> Cheers,
>
>
```