summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/arraysetops.py2
-rw-r--r--numpy/lib/function_base.py11
-rw-r--r--numpy/lib/shape_base.py18
-rw-r--r--numpy/lib/tests/test_function_base.py24
-rw-r--r--numpy/lib/tests/test_type_check.py8
-rw-r--r--numpy/lib/utils.py2
6 files changed, 27 insertions, 38 deletions
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py
index 7bd666029..b98517f3d 100644
--- a/numpy/lib/arraysetops.py
+++ b/numpy/lib/arraysetops.py
@@ -179,7 +179,7 @@ def test_unique1d_speed( plot_results = False ):
dt1s.append( dt1 )
dt2s.append( dt2 )
- assert numpy.alltrue( b == c )
+ assert numpy.alltrue( b == c)
print nItems
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index d8cd30f2c..a202f67cb 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -108,17 +108,16 @@ 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
- with a default axis of 0 instead of None.
+ over all dimensions of the array. Equivalent to a.mean(axis)
If an integer axis is given, this equals:
a.sum(axis) * 1.0 / len(a)
If axis is None, this equals:
- a.sum(axis) * 1.0 / product(a.shape)
+ a.sum(axis) * 1.0 / product(a.shape,axis=0)
If weights are given, result is:
- sum(a * weights) / sum(weights),
+ sum(a * weights,axis) / sum(weights,axis),
where the weights must have a's shape or be 1D with length the
size of a in the given axis. Integer weights are converted to
Float. Not specifying weights is equivalent to specifying
@@ -541,9 +540,9 @@ def extract(condition, arr):
"""Return the elements of ravel(arr) where ravel(condition) is True
(in 1D).
- Equivalent to compress(ravel(condition), ravel(arr)).
+ Equivalent to compress(ravel(condition), ravel(arr),0).
"""
- return _nx.take(ravel(arr), nonzero(ravel(condition))[0])
+ return _nx.take(ravel(arr), nonzero(ravel(condition))[0],axis=0)
def place(arr, mask, vals):
"""Similar to putmask arr[mask] = vals but the 1D array vals has the
diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py
index df0e9876d..03db2570a 100644
--- a/numpy/lib/shape_base.py
+++ b/numpy/lib/shape_base.py
@@ -32,7 +32,7 @@ def apply_along_axis(func1d,axis,arr,*args):
if isscalar(res):
outarr = zeros(outshape,asarray(res).dtype)
outarr[ind] = res
- Ntot = product(outshape)
+ Ntot = product(outshape,axis=0)
k = 1
while k < Ntot:
# increment the index
@@ -48,7 +48,7 @@ def apply_along_axis(func1d,axis,arr,*args):
k += 1
return outarr
else:
- Ntot = product(outshape)
+ Ntot = product(outshape,axis=0)
holdshape = outshape
outshape = list(arr.shape)
outshape[axis] = len(res)
@@ -326,12 +326,7 @@ def array_split(ary,indices_or_sections,axis = 0):
Caveats:
Currently, the default for axis is 0. This
means a 2D array is divided into multiple groups
- of rows. This seems like the appropriate default, but
- we've agreed most other functions should default to
- axis=-1. Perhaps we should use axis=-1 for consistency.
- However, we could also make the argument that NumPy
- works on "rows" by default. sum() sums up rows of
- values. split() will split data into rows. Opinions?
+ of rows. This seems like the appropriate default,
"""
try:
Ntotal = ary.shape[axis]
@@ -391,12 +386,7 @@ def split(ary,indices_or_sections,axis=0):
Caveats:
Currently, the default for axis is 0. This
means a 2D array is divided into multiple groups
- of rows. This seems like the appropriate default, but
- we've agreed most other functions should default to
- axis=-1. Perhaps we should use axis=-1 for consistency.
- However, we could also make the argument that NumPy
- works on "rows" by default. sum() sums up rows of
- values. split() will split data into rows. Opinions?
+ of rows. This seems like the appropriate default
"""
try: len(indices_or_sections)
except TypeError:
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index fdb2f270f..b548ce386 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -42,11 +42,11 @@ class test_all(NumpyTestCase):
class test_average(NumpyTestCase):
def check_basic(self):
y1 = array([1,2,3])
- assert(average(y1) == 2.)
+ assert(average(y1,axis=0) == 2.)
y2 = array([1.,2.,3.])
- assert(average(y2) == 2.)
+ assert(average(y2,axis=0) == 2.)
y3 = [0.,0.,0.]
- assert(average(y3) == 0.)
+ assert(average(y3,axis=0) == 0.)
y4 = ones((4,4))
y4[0,1] = 0
@@ -117,7 +117,7 @@ class test_amin(NumpyTestCase):
class test_ptp(NumpyTestCase):
def check_basic(self):
a = [3,4,5,10,-3,-5,6.0]
- assert_equal(ptp(a),15.0)
+ assert_equal(ptp(a,axis=0),15.0)
b = [[3,6.0, 9.0],
[4,10.0,5.0],
[8,3.0,2.0]]
@@ -132,7 +132,7 @@ class test_cumsum(NumpyTestCase):
float32,float64,complex64,complex128]:
a = array(ba,ctype)
a2 = array(ba2,ctype)
- assert_array_equal(cumsum(a), array([1,3,13,24,30,35,39],ctype))
+ assert_array_equal(cumsum(a,axis=0), array([1,3,13,24,30,35,39],ctype))
assert_array_equal(cumsum(a2,axis=0), array([[1,2,3,4],[6,8,10,13],
[16,11,14,18]],ctype))
assert_array_equal(cumsum(a2,axis=1),
@@ -153,7 +153,7 @@ class test_prod(NumpyTestCase):
self.failUnlessRaises(ArithmeticError, prod, a2, 1)
self.failUnlessRaises(ArithmeticError, prod, a)
else:
- assert_equal(prod(a),26400)
+ assert_equal(prod(a,axis=0),26400)
assert_array_equal(prod(a2,axis=0),
array([50,36,84,180],ctype))
assert_array_equal(prod(a2,axis=-1),array([24, 1890, 600],ctype))
@@ -305,35 +305,35 @@ class test_filterwindows(NumpyTestCase):
w=hanning(10)
assert_array_almost_equal(w,flipud(w),7)
#check known value
- assert_almost_equal(sum(w),4.500,4)
+ assert_almost_equal(sum(w,axis=0),4.500,4)
def check_hamming(self):
#check symmetry
w=hamming(10)
assert_array_almost_equal(w,flipud(w),7)
#check known value
- assert_almost_equal(sum(w),4.9400,4)
+ assert_almost_equal(sum(w,axis=0),4.9400,4)
def check_bartlett(self):
#check symmetry
w=bartlett(10)
assert_array_almost_equal(w,flipud(w),7)
#check known value
- assert_almost_equal(sum(w),4.4444,4)
+ assert_almost_equal(sum(w,axis=0),4.4444,4)
def check_blackman(self):
#check symmetry
w=blackman(10)
assert_array_almost_equal(w,flipud(w),7)
#check known value
- assert_almost_equal(sum(w),3.7800,4)
+ assert_almost_equal(sum(w,axis=0),3.7800,4)
class test_trapz(NumpyTestCase):
def check_simple(self):
r=trapz(exp(-1.0/2*(arange(-10,10,.1))**2)/sqrt(2*pi),dx=0.1)
#check integral of normal equals 1
- assert_almost_equal(sum(r),1,7)
+ assert_almost_equal(sum(r,axis=0),1,7)
class test_sinc(NumpyTestCase):
def check_simple(self):
@@ -348,7 +348,7 @@ class test_histogram(NumpyTestCase):
v=rand(n)
(a,b)=histogram(v)
#check if the sum of the bins equals the number of samples
- assert(sum(a)==n)
+ assert(sum(a,axis=0)==n)
#check that the bin counts are evenly spaced when the data is from a linear function
(a,b)=histogram(linspace(0,10,100))
assert(all(a==10))
diff --git a/numpy/lib/tests/test_type_check.py b/numpy/lib/tests/test_type_check.py
index b95760c8b..fba89e4c1 100644
--- a/numpy/lib/tests/test_type_check.py
+++ b/numpy/lib/tests/test_type_check.py
@@ -91,7 +91,7 @@ class test_iscomplex(NumpyTestCase):
def check_fail(self):
z = array([-1,0,1])
res = iscomplex(z)
- assert(not sometrue(res))
+ assert(not sometrue(res,axis=0))
def check_pass(self):
z = array([-1j,1,0])
res = iscomplex(z)
@@ -125,7 +125,7 @@ class test_isnan(NumpyTestCase):
def check_goodvalues(self):
z = array((-1.,0.,1.))
res = isnan(z) == 0
- assert_all(alltrue(res))
+ assert_all(alltrue(res,axis=0))
def check_posinf(self):
assert_all(isnan(array((1.,))/0.) == 0)
def check_neginf(self):
@@ -145,7 +145,7 @@ class test_isfinite(NumpyTestCase):
def check_goodvalues(self):
z = array((-1.,0.,1.))
res = isfinite(z) == 1
- assert_all(alltrue(res))
+ assert_all(alltrue(res,axis=0))
def check_posinf(self):
assert_all(isfinite(array((1.,))/0.) == 0)
def check_neginf(self):
@@ -165,7 +165,7 @@ class test_isinf(NumpyTestCase):
def check_goodvalues(self):
z = array((-1.,0.,1.))
res = isinf(z) == 0
- assert_all(alltrue(res))
+ assert_all(alltrue(res,axis=0))
def check_posinf(self):
assert_all(isinf(array((1.,))/0.) == 1)
def check_posinf_scalar(self):
diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py
index db7c00db6..deca8fa06 100644
--- a/numpy/lib/utils.py
+++ b/numpy/lib/utils.py
@@ -126,7 +126,7 @@ def who(vardict=None):
namestr = name
original=1
shapestr = " x ".join(map(str, var.shape))
- bytestr = str(var.itemsize*product(var.shape))
+ bytestr = str(var.itemsize*product(var.shape,axis=0))
sta.append([namestr, shapestr, bytestr, var.dtype.name,
original])