summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/ma.py22
-rw-r--r--numpy/core/tests/test_ma.py20
-rw-r--r--numpy/lib/function_base.py5
-rw-r--r--numpy/numarray/functions.py5
-rw-r--r--numpy/oldnumeric/functions.py6
-rw-r--r--numpy/oldnumeric/ma.py10
-rw-r--r--numpy/oldnumeric/misc.py4
7 files changed, 44 insertions, 28 deletions
diff --git a/numpy/core/ma.py b/numpy/core/ma.py
index 5c93753a1..591ad801a 100644
--- a/numpy/core/ma.py
+++ b/numpy/core/ma.py
@@ -448,7 +448,7 @@ def nonzero(a):
"""returns the indices of the elements of a which are not zero
and not masked
"""
- return asarray(filled(a, 0).nonzero())
+ return numeric.asarray(filled(a, 0).nonzero())
around = masked_unary_operation(fromnumeric.round_)
floor = masked_unary_operation(umath.floor)
@@ -1532,7 +1532,7 @@ def resize (a, new_shape):
result.set_fill_value(get_fill_value(a))
return result
-def repeat(a, repeats, axis=0):
+def repeat(a, repeats, axis=None):
"""repeat elements of a repeats times along axis
repeats is a sequence of length a.shape[axis]
telling how many times to repeat each element.
@@ -1603,8 +1603,8 @@ def masked_array (a, mask=nomask, fill_value=None):
sum = add.reduce
product = multiply.reduce
-def average (a, axis=0, weights=None, returned = 0):
- """average(a, axis=0, weights=None)
+def average (a, axis=None, weights=None, returned = 0):
+ """average(a, axis=None, weights=None)
Computes average along indicated axis.
If axis is None, average over the entire array
Inputs can be integer or floating types; result is of type float.
@@ -1858,7 +1858,7 @@ def swapaxes (a, axis1, axis2):
mask=numeric.swapaxes(m, axis1, axis2),)
-def take (a, indices, axis=0, out=None, mode='raise'):
+def take (a, indices, axis=None, out=None, mode='raise'):
"returns selection of items from a."
m = getmask(a)
# d = masked_array(a).raw_data()
@@ -2168,14 +2168,14 @@ del _compress
array.conj = array.conjugate = _m(conjugate)
array.copy = _m(not_implemented)
-def _cumprod(self, axis=0, dtype=None, out=None):
+def _cumprod(self, axis=None, dtype=None, out=None):
m = self.mask
if m is not nomask:
m = umath.logical_or.accumulate(self.mask, axis)
return MaskedArray(data = self.filled(1).cumprod(axis, dtype), mask=m)
array.cumprod = _m(_cumprod)
-def _cumsum(self, axis=0, dtype=None, out=None):
+def _cumsum(self, axis=None, dtype=None, out=None):
m = self.mask
if m is not nomask:
m = umath.logical_or.accumulate(self.mask, axis)
@@ -2214,7 +2214,7 @@ array.newbyteorder = _m(not_implemented)
array.nonzero = _m(nonzero)
array.prod = _m(product)
-def _ptp(a,axis=0,out=None):
+def _ptp(a,axis=None,out=None):
return a.max(axis,out)-a.min(axis)
array.ptp = _m(_ptp)
array.repeat = _m(repeat)
@@ -2244,15 +2244,15 @@ array.tofile = _m(not_implemented)
array.trace = _m(trace)
array.transpose = _m(transpose)
-def _var(self,axis=0,dtype=None, out=None):
+def _var(self,axis=None,dtype=None, out=None):
if axis is None:
- return asarray(self.compressed()).var()
+ return numeric.asarray(self.compressed()).var()
a = self.swapaxes(axis,0)
a = a - a.mean(axis=0)
a *= a
a /= a.count(axis=0)
return a.swapaxes(0,axis).sum(axis)
-def _std(self,axis=0,dtype=None, out=None):
+def _std(self,axis=None, dtype=None, out=None):
return (self.var(axis,dtype))**0.5
array.var = _m(_var)
array.std = _m(_std)
diff --git a/numpy/core/tests/test_ma.py b/numpy/core/tests/test_ma.py
index 540e64c8a..3607b965b 100644
--- a/numpy/core/tests/test_ma.py
+++ b/numpy/core/tests/test_ma.py
@@ -267,9 +267,9 @@ class test_ma(NumpyTestCase):
y4 = resize(x4, (8,))
self.failUnless( eq(concatenate([x4,x4]), y4))
self.failUnless( eq(getmask(y4),[0,0,1,0,0,0,1,0]))
- y5 = repeat(x4, (2,2,2,2))
+ y5 = repeat(x4, (2,2,2,2), axis=0)
self.failUnless( eq(y5, [0,0,1,1,2,2,3,3]))
- y6 = repeat(x4, 2)
+ y6 = repeat(x4, 2, axis=0)
self.failUnless( eq(y5, y6))
def check_testPut(self):
@@ -523,10 +523,10 @@ class test_ma(NumpyTestCase):
ott = array([0.,1.,2.,3.], mask=[1,0,0,0])
ott=ott.reshape(2,2)
ott[:,1] = masked
- self.failUnless(eq(average(ott), [2.0, 0.0]))
+ self.failUnless(eq(average(ott,axis=0), [2.0, 0.0]))
self.failUnless(average(ott,axis=1)[0] is masked)
- self.failUnless(eq([2.,0.], average(ott)))
- result, wts = average(ott, returned=1)
+ self.failUnless(eq([2.,0.], average(ott, axis=0)))
+ result, wts = average(ott, axis=0, returned=1)
self.failUnless(eq(wts, [1., 0.]))
def check_testAverage2(self):
@@ -534,8 +534,8 @@ class test_ma(NumpyTestCase):
w1 = [0,1,1,1,1,0]
w2 = [[0,1,1,1,1,0],[1,0,0,0,0,1]]
x=arange(6)
- self.failUnless(allclose(average(x), 2.5))
- self.failUnless(allclose(average(x, weights=w1), 2.5))
+ self.failUnless(allclose(average(x, axis=0), 2.5))
+ self.failUnless(allclose(average(x, axis=0, weights=w1), 2.5))
y=array([arange(6), 2.0*arange(6)])
self.failUnless(allclose(average(y, None), numpy.add.reduce(numpy.arange(6))*3./12.))
self.failUnless(allclose(average(y, axis=0), numpy.arange(6) * 3./2.))
@@ -557,7 +557,7 @@ class test_ma(NumpyTestCase):
self.failUnless(allclose(average(z, None), 20./6.))
self.failUnless(allclose(average(z, axis=0), [0.,1.,99.,99.,4.0, 7.5]))
self.failUnless(allclose(average(z, axis=1), [2.5, 5.0]))
- self.failUnless(allclose( average(z,weights=w2), [0.,1., 99., 99., 4.0, 10.0]))
+ self.failUnless(allclose( average(z,axis=0, weights=w2), [0.,1., 99., 99., 4.0, 10.0]))
a = arange(6)
b = arange(6) * 3
@@ -572,9 +572,9 @@ class test_ma(NumpyTestCase):
self.failUnless(shape(w2) == shape(r2))
a2d = array([[1,2],[0,4]], float)
a2dm = masked_array(a2d, [[0,0],[1,0]])
- a2da = average(a2d)
+ a2da = average(a2d, axis=0)
self.failUnless(eq (a2da, [0.5, 3.0]))
- a2dma = average(a2dm)
+ a2dma = average(a2dm, axis=0)
self.failUnless(eq( a2dma, [1.0, 3.0]))
a2dma = average(a2dm, axis=None)
self.failUnless(eq(a2dma, 7./3.))
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 098632ead..a62b3569e 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -1,4 +1,3 @@
-
__all__ = ['logspace', 'linspace',
'select', 'piecewise', 'trim_zeros',
'copy', 'iterable', #'base_repr', 'binary_repr',
@@ -100,8 +99,8 @@ def histogram(a, bins=10, range=None, normed=False):
else:
return n, bins
-def average(a, axis=0, weights=None, returned=False):
- """average(a, axis=0, weights=None, returned=False)
+def average(a, axis=None, weights=None, returned=False):
+ """average(a, axis=None weights=None, returned=False)
Average the array over the given axis. If the axis is None, average
over all dimensions of the array. Equivalent to a.mean(axis), but
diff --git a/numpy/numarray/functions.py b/numpy/numarray/functions.py
index c990fe7e9..55922e9fe 100644
--- a/numpy/numarray/functions.py
+++ b/numpy/numarray/functions.py
@@ -42,7 +42,7 @@ import os, sys, math, operator
from numpy import dot as matrixmultiply, dot, vdot, ravel, concatenate, all,\
allclose, any, around, argsort, array_equal, array_equiv,\
- array_str, array_repr, average, CLIP, RAISE, WRAP, clip, concatenate, \
+ array_str, array_repr, CLIP, RAISE, WRAP, clip, concatenate, \
diagonal, e, pi, fromfunction, indices, inner as innerproduct, nonzero, \
outer as outerproduct, kron as kroneckerproduct, lexsort, putmask, rank, \
resize, searchsorted, shape, size, sort, swapaxes, trace, transpose
@@ -453,3 +453,6 @@ def newobj(self, type):
def togglebyteorder(self):
self.dtype=self.dtype.newbyteorder()
+
+def average(a, axis=0, weights=None, returned=0):
+ return N.average(a, axis, weights, returned)
diff --git a/numpy/oldnumeric/functions.py b/numpy/oldnumeric/functions.py
index e18f12aa8..4e3f12639 100644
--- a/numpy/oldnumeric/functions.py
+++ b/numpy/oldnumeric/functions.py
@@ -9,7 +9,8 @@ __all__ = ['take', 'repeat', 'sum', 'product', 'sometrue', 'alltrue',
'cumsum', 'cumproduct', 'compress',
'ones', 'empty', 'identity', 'zeros', 'array', 'asarray',
'nonzero', 'reshape', 'arange', 'fromstring', 'ravel', 'trace',
- 'indices', 'where','sarray','cross_product', 'argmax', 'argmin']
+ 'indices', 'where','sarray','cross_product', 'argmax', 'argmin',
+ 'average']
def take(a, indicies, axis=0):
return N.take(a, indicies, axis)
@@ -115,3 +116,6 @@ def where(condition, x, y):
def cross_product(a, b, axis1=-1, axis2=-1):
return N.cross(a, b, axis1, axis2)
+
+def average(a, axis=0, weights=None, returned=False):
+ return N.average(a, axis, weights, returned)
diff --git a/numpy/oldnumeric/ma.py b/numpy/oldnumeric/ma.py
index c78fcc200..857c554ec 100644
--- a/numpy/oldnumeric/ma.py
+++ b/numpy/oldnumeric/ma.py
@@ -2,4 +2,14 @@
# instead of None
from numpy.core.ma import *
+import numpy.core.ma as nca
+
+def repeat(a, repeats, axis=0):
+ return nca.repeat(a, repeats, axis)
+
+def average(a, axis=0, weights=None, returned=0):
+ return nca.average(a, axis, weights, returned)
+
+def take(a, indices, axis=0):
+ return nca.average(a, indices, axis=0)
diff --git a/numpy/oldnumeric/misc.py b/numpy/oldnumeric/misc.py
index e8c2e3c00..a6c13d780 100644
--- a/numpy/oldnumeric/misc.py
+++ b/numpy/oldnumeric/misc.py
@@ -7,7 +7,7 @@ __all__ = ['load', 'sort', 'copy_reg', 'clip', 'putmask', 'Unpickler', 'rank',
'pi', 'math', 'concatenate',
'around', 'vdot', 'transpose', 'array2string', 'diagonal',
'searchsorted', 'put', 'fromfunction', 'copy', 'resize',
- 'array_repr', 'e', 'StringIO', 'pickle', 'average',
+ 'array_repr', 'e', 'StringIO', 'pickle',
'argsort', 'convolve', 'loads', 'cross_correlate',
'Pickler', 'dot', 'outerproduct', 'innerproduct']
@@ -22,7 +22,7 @@ from pickle import load, loads
from numpy import sort, clip, putmask, rank, sign, shape, allclose, size,\
choose, swapaxes, array_str, array_repr, e, pi, \
fromfunction, resize, around, concatenate, vdot, transpose, \
- diagonal, searchsorted, put, average, argsort, convolve, dot, \
+ diagonal, searchsorted, put, argsort, convolve, dot, \
outer as outerproduct, inner as innerproduct, correlate as cross_correlate
from array_printer import array2string