Author: Alex Gaynor <alex.gay...@gmail.com> Branch: Changeset: r44977:549f8479862d Date: 2011-06-16 14:41 -0700 http://bitbucket.org/pypy/pypy/changeset/549f8479862d/
Log: Added numpy.average, but don't implemented weighted averages for now. diff --git a/pypy/module/micronumpy/__init__.py b/pypy/module/micronumpy/__init__.py --- a/pypy/module/micronumpy/__init__.py +++ b/pypy/module/micronumpy/__init__.py @@ -22,5 +22,6 @@ } appleveldefs = { + 'average': 'app_numpy.average', 'mean': 'app_numpy.mean', } diff --git a/pypy/module/micronumpy/app_numpy.py b/pypy/module/micronumpy/app_numpy.py --- a/pypy/module/micronumpy/app_numpy.py +++ b/pypy/module/micronumpy/app_numpy.py @@ -1,5 +1,9 @@ import numpy +def average(a): + # This implements a weighted average, for now we don't implement the + # weighting, just the average part! + return mean(a) def mean(a): if not hasattr(a, "mean"): diff --git a/pypy/module/micronumpy/test/test_module.py b/pypy/module/micronumpy/test/test_module.py new file mode 100644 --- /dev/null +++ b/pypy/module/micronumpy/test/test_module.py @@ -0,0 +1,13 @@ +from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest + + +class AppTestNumPyModule(BaseNumpyAppTest): + def test_mean(self): + from numpy import array, mean + assert mean(array(range(5))) == 2.0 + assert mean(range(5)) == 2.0 + + def test_average(self): + from numpy import array, average + assert average(range(10)) == 4.5 + assert average(array(range(10))) == 4.5 \ No newline at end of file diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py --- a/pypy/module/micronumpy/test/test_numarray.py +++ b/pypy/module/micronumpy/test/test_numarray.py @@ -195,6 +195,4 @@ from numpy import array, mean a = array(range(5)) assert a.mean() == 2.0 - assert mean(a) == 2.0 - assert mean(range(5)) == 2.0 assert a[:4].mean() == 1.5 \ No newline at end of file _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit