summaryrefslogtreecommitdiff
path: root/numpy/lib/tests
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2013-08-18 16:19:20 -0700
committerCharles Harris <charlesr.harris@gmail.com>2013-08-18 16:19:20 -0700
commit6c729b4423857850e6553cf6c2d0fc8b026036dd (patch)
tree330ce703eb02d20f96099c3fe0fc36ae33d4905b /numpy/lib/tests
parent13b0b272f764c14bc4ac34f5b19fd030d9c611a4 (diff)
parentfbd6510d58a47ea0d166c48a82793f05425406e4 (diff)
downloadnumpy-6c729b4423857850e6553cf6c2d0fc8b026036dd.tar.gz
Merge pull request #3635 from charris/giant-style-cleanup
Giant style cleanup
Diffstat (limited to 'numpy/lib/tests')
-rw-r--r--numpy/lib/tests/test_arraysetops.py42
-rw-r--r--numpy/lib/tests/test_financial.py126
-rw-r--r--numpy/lib/tests/test_format.py24
-rw-r--r--numpy/lib/tests/test_function_base.py112
-rw-r--r--numpy/lib/tests/test_index_tricks.py162
-rw-r--r--numpy/lib/tests/test_io.py4
-rw-r--r--numpy/lib/tests/test_nanfunctions.py8
-rw-r--r--numpy/lib/tests/test_polynomial.py50
-rw-r--r--numpy/lib/tests/test_recfunctions.py14
-rw-r--r--numpy/lib/tests/test_regression.py76
-rw-r--r--numpy/lib/tests/test_shape_base.py330
-rw-r--r--numpy/lib/tests/test_stride_tricks.py144
-rw-r--r--numpy/lib/tests/test_twodim_base.py202
-rw-r--r--numpy/lib/tests/test_type_check.py140
-rw-r--r--numpy/lib/tests/test_ufunclike.py2
15 files changed, 718 insertions, 718 deletions
diff --git a/numpy/lib/tests/test_arraysetops.py b/numpy/lib/tests/test_arraysetops.py
index 4ba6529e4..7e8a7a6f3 100644
--- a/numpy/lib/tests/test_arraysetops.py
+++ b/numpy/lib/tests/test_arraysetops.py
@@ -61,8 +61,8 @@ class TestSetOps(TestCase):
# test for structured arrays
dt = [('', 'i'), ('', 'i')]
- aa = np.array(list(zip(a,a)), dt)
- bb = np.array(list(zip(b,b)), dt)
+ aa = np.array(list(zip(a, a)), dt)
+ bb = np.array(list(zip(b, b)), dt)
check_all(aa, bb, i1, i2, dt)
@@ -83,7 +83,7 @@ class TestSetOps(TestCase):
c = intersect1d( a, b )
assert_array_equal( c, ed )
- assert_array_equal([], intersect1d([],[]))
+ assert_array_equal([], intersect1d([], []))
def test_setxor1d( self ):
a = np.array( [5, 7, 1, 2] )
@@ -107,19 +107,19 @@ class TestSetOps(TestCase):
c = setxor1d( a, b )
assert_array_equal( c, ec )
- assert_array_equal([], setxor1d([],[]))
+ assert_array_equal([], setxor1d([], []))
def test_ediff1d(self):
zero_elem = np.array([])
one_elem = np.array([1])
- two_elem = np.array([1,2])
+ two_elem = np.array([1, 2])
- assert_array_equal([],ediff1d(zero_elem))
- assert_array_equal([0],ediff1d(zero_elem,to_begin=0))
- assert_array_equal([0],ediff1d(zero_elem,to_end=0))
- assert_array_equal([-1,0],ediff1d(zero_elem,to_begin=-1,to_end=0))
- assert_array_equal([],ediff1d(one_elem))
- assert_array_equal([1],ediff1d(two_elem))
+ assert_array_equal([], ediff1d(zero_elem))
+ assert_array_equal([0], ediff1d(zero_elem, to_begin=0))
+ assert_array_equal([0], ediff1d(zero_elem, to_end=0))
+ assert_array_equal([-1, 0], ediff1d(zero_elem, to_begin=-1, to_end=0))
+ assert_array_equal([], ediff1d(one_elem))
+ assert_array_equal([1], ediff1d(two_elem))
def test_in1d(self):
# we use two different sizes for the b array here to test the
@@ -182,8 +182,8 @@ class TestSetOps(TestCase):
assert_array_equal(in1d([], []), [])
def test_in1d_char_array( self ):
- a = np.array(['a', 'b', 'c','d','e','c','e','b'])
- b = np.array(['a','c'])
+ a = np.array(['a', 'b', 'c', 'd', 'e', 'c', 'e', 'b'])
+ b = np.array(['a', 'c'])
ec = np.array([True, False, True, False, False, True, False, False])
c = in1d(a, b)
@@ -202,9 +202,9 @@ class TestSetOps(TestCase):
def test_in1d_ravel(self):
# Test that in1d ravels its input arrays. This is not documented
# behavior however. The test is to ensure consistentency.
- a = np.arange(6).reshape(2,3)
- b = np.arange(3,9).reshape(3,2)
- long_b = np.arange(3, 63).reshape(30,2)
+ a = np.arange(6).reshape(2, 3)
+ b = np.arange(3, 9).reshape(3, 2)
+ long_b = np.arange(3, 63).reshape(30, 2)
ec = np.array([False, False, False, True, True, True])
assert_array_equal(in1d(a, b, assume_unique=True), ec)
@@ -220,7 +220,7 @@ class TestSetOps(TestCase):
c = union1d( a, b )
assert_array_equal( c, ec )
- assert_array_equal([], union1d([],[]))
+ assert_array_equal([], union1d([], []))
def test_setdiff1d( self ):
a = np.array( [6, 5, 4, 7, 1, 2, 7, 4] )
@@ -236,12 +236,12 @@ class TestSetOps(TestCase):
c = setdiff1d( a, b )
assert_array_equal( c, ec )
- assert_array_equal([], setdiff1d([],[]))
+ assert_array_equal([], setdiff1d([], []))
def test_setdiff1d_char_array(self):
- a = np.array(['a','b','c'])
- b = np.array(['a','b','s'])
- assert_array_equal(setdiff1d(a,b),np.array(['c']))
+ a = np.array(['a', 'b', 'c'])
+ b = np.array(['a', 'b', 's'])
+ assert_array_equal(setdiff1d(a, b), np.array(['c']))
def test_manyways( self ):
a = np.array( [5, 7, 1, 2, 8] )
diff --git a/numpy/lib/tests/test_financial.py b/numpy/lib/tests/test_financial.py
index 1a276a429..1894da8cb 100644
--- a/numpy/lib/tests/test_financial.py
+++ b/numpy/lib/tests/test_financial.py
@@ -5,7 +5,7 @@ import numpy as np
class TestFinancial(TestCase):
def test_rate(self):
- assert_almost_equal(np.rate(10,0,-3500,10000),
+ assert_almost_equal(np.rate(10, 0, -3500, 10000),
0.1107, 4)
def test_irr(self):
@@ -14,127 +14,127 @@ class TestFinancial(TestCase):
0.0524, 2)
def test_pv(self):
- assert_almost_equal(np.pv(0.07,20,12000,0),
+ assert_almost_equal(np.pv(0.07, 20, 12000, 0),
-127128.17, 2)
def test_fv(self):
- assert_almost_equal(np.fv(0.075, 20, -2000,0,0),
+ assert_almost_equal(np.fv(0.075, 20, -2000, 0, 0),
86609.36, 2)
def test_pmt(self):
- assert_almost_equal(np.pmt(0.08/12,5*12,15000),
+ assert_almost_equal(np.pmt(0.08/12, 5*12, 15000),
-304.146, 3)
def test_ppmt(self):
- np.round(np.ppmt(0.1/12,1,60,55000),2) == 710.25
+ np.round(np.ppmt(0.1/12, 1, 60, 55000), 2) == 710.25
def test_ipmt(self):
- np.round(np.ipmt(0.1/12,1,24,2000),2) == 16.67
+ np.round(np.ipmt(0.1/12, 1, 24, 2000), 2) == 16.67
def test_nper(self):
- assert_almost_equal(np.nper(0.075,-2000,0,100000.),
+ assert_almost_equal(np.nper(0.075, -2000, 0, 100000.),
21.54, 2)
def test_nper2(self):
- assert_almost_equal(np.nper(0.0,-2000,0,100000.),
+ assert_almost_equal(np.nper(0.0, -2000, 0, 100000.),
50.0, 1)
def test_npv(self):
- assert_almost_equal(np.npv(0.05,[-15000,1500,2500,3500,4500,6000]),
+ assert_almost_equal(np.npv(0.05, [-15000, 1500, 2500, 3500, 4500, 6000]),
122.89, 2)
def test_mirr(self):
- val = [-4500,-800,800,800,600,600,800,800,700,3000]
+ val = [-4500, -800, 800, 800, 600, 600, 800, 800, 700, 3000]
assert_almost_equal(np.mirr(val, 0.08, 0.055), 0.0666, 4)
- val = [-120000,39000,30000,21000,37000,46000]
+ val = [-120000, 39000, 30000, 21000, 37000, 46000]
assert_almost_equal(np.mirr(val, 0.10, 0.12), 0.126094, 6)
- val = [100,200,-50,300,-200]
+ val = [100, 200, -50, 300, -200]
assert_almost_equal(np.mirr(val, 0.05, 0.06), 0.3428, 4)
- val = [39000,30000,21000,37000,46000]
+ val = [39000, 30000, 21000, 37000, 46000]
assert_(np.isnan(np.mirr(val, 0.10, 0.12)))
def test_when(self):
#begin
- assert_almost_equal(np.rate(10,20,-3500,10000,1),
- np.rate(10,20,-3500,10000,'begin'), 4)
+ assert_almost_equal(np.rate(10, 20, -3500, 10000, 1),
+ np.rate(10, 20, -3500, 10000, 'begin'), 4)
#end
- assert_almost_equal(np.rate(10,20,-3500,10000),
- np.rate(10,20,-3500,10000,'end'), 4)
- assert_almost_equal(np.rate(10,20,-3500,10000,0),
- np.rate(10,20,-3500,10000,'end'), 4)
+ assert_almost_equal(np.rate(10, 20, -3500, 10000),
+ np.rate(10, 20, -3500, 10000, 'end'), 4)
+ assert_almost_equal(np.rate(10, 20, -3500, 10000, 0),
+ np.rate(10, 20, -3500, 10000, 'end'), 4)
# begin
- assert_almost_equal(np.pv(0.07,20,12000,0,1),
- np.pv(0.07,20,12000,0,'begin'), 2)
+ assert_almost_equal(np.pv(0.07, 20, 12000, 0, 1),
+ np.pv(0.07, 20, 12000, 0, 'begin'), 2)
# end
- assert_almost_equal(np.pv(0.07,20,12000,0),
- np.pv(0.07,20,12000,0,'end'), 2)
- assert_almost_equal(np.pv(0.07,20,12000,0,0),
- np.pv(0.07,20,12000,0,'end'), 2)
+ assert_almost_equal(np.pv(0.07, 20, 12000, 0),
+ np.pv(0.07, 20, 12000, 0, 'end'), 2)
+ assert_almost_equal(np.pv(0.07, 20, 12000, 0, 0),
+ np.pv(0.07, 20, 12000, 0, 'end'), 2)
# begin
- assert_almost_equal(np.fv(0.075, 20, -2000,0,1),
- np.fv(0.075, 20, -2000,0,'begin'), 4)
+ assert_almost_equal(np.fv(0.075, 20, -2000, 0, 1),
+ np.fv(0.075, 20, -2000, 0, 'begin'), 4)
# end
- assert_almost_equal(np.fv(0.075, 20, -2000,0),
- np.fv(0.075, 20, -2000,0,'end'), 4)
- assert_almost_equal(np.fv(0.075, 20, -2000,0,0),
- np.fv(0.075, 20, -2000,0,'end'), 4)
+ assert_almost_equal(np.fv(0.075, 20, -2000, 0),
+ np.fv(0.075, 20, -2000, 0, 'end'), 4)
+ assert_almost_equal(np.fv(0.075, 20, -2000, 0, 0),
+ np.fv(0.075, 20, -2000, 0, 'end'), 4)
# begin
- assert_almost_equal(np.pmt(0.08/12,5*12,15000.,0,1),
- np.pmt(0.08/12,5*12,15000.,0,'begin'), 4)
+ assert_almost_equal(np.pmt(0.08/12, 5*12, 15000., 0, 1),
+ np.pmt(0.08/12, 5*12, 15000., 0, 'begin'), 4)
# end
- assert_almost_equal(np.pmt(0.08/12,5*12,15000.,0),
- np.pmt(0.08/12,5*12,15000.,0,'end'), 4)
- assert_almost_equal(np.pmt(0.08/12,5*12,15000.,0,0),
- np.pmt(0.08/12,5*12,15000.,0,'end'), 4)
+ assert_almost_equal(np.pmt(0.08/12, 5*12, 15000., 0),
+ np.pmt(0.08/12, 5*12, 15000., 0, 'end'), 4)
+ assert_almost_equal(np.pmt(0.08/12, 5*12, 15000., 0, 0),
+ np.pmt(0.08/12, 5*12, 15000., 0, 'end'), 4)
# begin
- assert_almost_equal(np.ppmt(0.1/12,1,60,55000,0,1),
- np.ppmt(0.1/12,1,60,55000,0,'begin'), 4)
+ assert_almost_equal(np.ppmt(0.1/12, 1, 60, 55000, 0, 1),
+ np.ppmt(0.1/12, 1, 60, 55000, 0, 'begin'), 4)
# end
- assert_almost_equal(np.ppmt(0.1/12,1,60,55000,0),
- np.ppmt(0.1/12,1,60,55000,0,'end'), 4)
- assert_almost_equal(np.ppmt(0.1/12,1,60,55000,0,0),
- np.ppmt(0.1/12,1,60,55000,0,'end'), 4)
+ assert_almost_equal(np.ppmt(0.1/12, 1, 60, 55000, 0),
+ np.ppmt(0.1/12, 1, 60, 55000, 0, 'end'), 4)
+ assert_almost_equal(np.ppmt(0.1/12, 1, 60, 55000, 0, 0),
+ np.ppmt(0.1/12, 1, 60, 55000, 0, 'end'), 4)
# begin
- assert_almost_equal(np.ipmt(0.1/12,1,24,2000,0,1),
- np.ipmt(0.1/12,1,24,2000,0,'begin'), 4)
+ assert_almost_equal(np.ipmt(0.1/12, 1, 24, 2000, 0, 1),
+ np.ipmt(0.1/12, 1, 24, 2000, 0, 'begin'), 4)
# end
- assert_almost_equal(np.ipmt(0.1/12,1,24,2000,0),
- np.ipmt(0.1/12,1,24,2000,0,'end'), 4)
- assert_almost_equal(np.ipmt(0.1/12,1,24,2000,0,0),
- np.ipmt(0.1/12,1,24,2000,0,'end'), 4)
+ assert_almost_equal(np.ipmt(0.1/12, 1, 24, 2000, 0),
+ np.ipmt(0.1/12, 1, 24, 2000, 0, 'end'), 4)
+ assert_almost_equal(np.ipmt(0.1/12, 1, 24, 2000, 0, 0),
+ np.ipmt(0.1/12, 1, 24, 2000, 0, 'end'), 4)
# begin
- assert_almost_equal(np.nper(0.075,-2000,0,100000.,1),
- np.nper(0.075,-2000,0,100000.,'begin'), 4)
+ assert_almost_equal(np.nper(0.075, -2000, 0, 100000., 1),
+ np.nper(0.075, -2000, 0, 100000., 'begin'), 4)
# end
- assert_almost_equal(np.nper(0.075,-2000,0,100000.),
- np.nper(0.075,-2000,0,100000.,'end'), 4)
- assert_almost_equal(np.nper(0.075,-2000,0,100000.,0),
- np.nper(0.075,-2000,0,100000.,'end'), 4)
+ assert_almost_equal(np.nper(0.075, -2000, 0, 100000.),
+ np.nper(0.075, -2000, 0, 100000., 'end'), 4)
+ assert_almost_equal(np.nper(0.075, -2000, 0, 100000., 0),
+ np.nper(0.075, -2000, 0, 100000., 'end'), 4)
def test_broadcast(self):
- assert_almost_equal(np.nper(0.075,-2000,0,100000.,[0,1]),
- [ 21.5449442 , 20.76156441], 4)
+ assert_almost_equal(np.nper(0.075, -2000, 0, 100000., [0, 1]),
+ [ 21.5449442, 20.76156441], 4)
- assert_almost_equal(np.ipmt(0.1/12,list(range(5)), 24, 2000),
+ assert_almost_equal(np.ipmt(0.1/12, list(range(5)), 24, 2000),
[-17.29165168, -16.66666667, -16.03647345,
-15.40102862, -14.76028842], 4)
- assert_almost_equal(np.ppmt(0.1/12,list(range(5)), 24, 2000),
- [-74.998201 , -75.62318601, -76.25337923,
+ assert_almost_equal(np.ppmt(0.1/12, list(range(5)), 24, 2000),
+ [-74.998201, -75.62318601, -76.25337923,
-76.88882405, -77.52956425], 4)
- assert_almost_equal(np.ppmt(0.1/12,list(range(5)), 24, 2000, 0,
- [0,0,1,'end','begin']),
- [-74.998201 , -75.62318601, -75.62318601,
+ assert_almost_equal(np.ppmt(0.1/12, list(range(5)), 24, 2000, 0,
+ [0, 0, 1, 'end', 'begin']),
+ [-74.998201, -75.62318601, -75.62318601,
-76.88882405, -76.88882405], 4)
if __name__ == "__main__":
diff --git a/numpy/lib/tests/test_format.py b/numpy/lib/tests/test_format.py
index 8b809891f..694dc4591 100644
--- a/numpy/lib/tests/test_format.py
+++ b/numpy/lib/tests/test_format.py
@@ -331,11 +331,11 @@ for scalar in scalars:
# 1-D
basic,
# 2-D C-contiguous
- basic.reshape((3,5)),
+ basic.reshape((3, 5)),
# 2-D F-contiguous
- basic.reshape((3,5)).T,
+ basic.reshape((3, 5)).T,
# 2-D non-contiguous
- basic.reshape((3,5))[::-1,::2],
+ basic.reshape((3, 5))[::-1, ::2],
])
# More complicated record arrays.
@@ -354,8 +354,8 @@ Pdescr = [
# A plain list of tuples with values for testing:
PbufferT = [
# x y z
- ([3,2], [[6.,4.],[6.,4.]], 8),
- ([4,3], [[7.,5.],[7.,5.]], 9),
+ ([3, 2], [[6., 4.], [6., 4.]], 8),
+ ([4, 3], [[7., 5.], [7., 5.]], 9),
]
@@ -394,8 +394,8 @@ NbufferT = [
# x Info color info y z
# value y2 Info2 name z2 Name Value
# name value y3 z3
- ([3,2], (6j, 6., ('nn', [6j,4j], [6.,4.], [1,2]), 'NN', True), 'cc', ('NN', 6j), [[6.,4.],[6.,4.]], 8),
- ([4,3], (7j, 7., ('oo', [7j,5j], [7.,5.], [2,1]), 'OO', False), 'dd', ('OO', 7j), [[7.,5.],[7.,5.]], 9),
+ ([3, 2], (6j, 6., ('nn', [6j, 4j], [6., 4.], [1, 2]), 'NN', True), 'cc', ('NN', 6j), [[6., 4.], [6., 4.]], 8),
+ ([4, 3], (7j, 7., ('oo', [7j, 5j], [7., 5.], [2, 1]), 'OO', False), 'dd', ('OO', 7j), [[7., 5.], [7., 5.]], 9),
]
record_arrays = [
@@ -520,7 +520,7 @@ def test_bad_magic_args():
def test_large_header():
s = BytesIO()
d = {'a':1,'b':2}
- format.write_array_header_1_0(s,d)
+ format.write_array_header_1_0(s, d)
s = BytesIO()
d = {'a':1,'b':2,'c':'x'*256*256}
@@ -538,18 +538,18 @@ def test_bad_header():
assert_raises(ValueError, format.read_array_header_1_0, s)
# headers without the exact keys required should fail
- d = {"shape":(1,2),
+ d = {"shape":(1, 2),
"descr":"x"}
s = BytesIO()
- format.write_array_header_1_0(s,d)
+ format.write_array_header_1_0(s, d)
assert_raises(ValueError, format.read_array_header_1_0, s)
- d = {"shape":(1,2),
+ d = {"shape":(1, 2),
"fortran_order":False,
"descr":"x",
"extrakey":-1}
s = BytesIO()
- format.write_array_header_1_0(s,d)
+ format.write_array_header_1_0(s, d)
assert_raises(ValueError, format.read_array_header_1_0, s)
if __name__ == "__main__":
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index 65519d0bc..28f094653 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -174,10 +174,10 @@ class TestInsert(TestCase):
assert_equal(insert(a, 0, 1), [1, 1, 2, 3])
assert_equal(insert(a, 3, 1), [1, 2, 3, 1])
assert_equal(insert(a, [1, 1, 1], [1, 2, 3]), [1, 1, 2, 3, 2, 3])
- assert_equal(insert(a, 1,[1,2,3]), [1, 1, 2, 3, 2, 3])
- assert_equal(insert(a,[1,-1,3],9),[1,9,2,9,3,9])
- assert_equal(insert(a,slice(-1,None,-1), 9),[9,1,9,2,9,3])
- assert_equal(insert(a,[-1,1,3], [7,8,9]),[1,8,2,7,3,9])
+ assert_equal(insert(a, 1, [1, 2, 3]), [1, 1, 2, 3, 2, 3])
+ assert_equal(insert(a, [1, -1, 3], 9), [1, 9, 2, 9, 3, 9])
+ assert_equal(insert(a, slice(-1, None, -1), 9), [9, 1, 9, 2, 9, 3])
+ assert_equal(insert(a, [-1, 1, 3], [7, 8, 9]), [1, 8, 2, 7, 3, 9])
b = np.array([0, 1], dtype=np.float64)
assert_equal(insert(b, 0, b[0]), [0., 0., 1.])
assert_equal(insert(b, [], []), b)
@@ -185,42 +185,42 @@ class TestInsert(TestCase):
#assert_equal(insert(a, np.array([True]*4), 9), [9,1,9,2,9,3,9])
with warnings.catch_warnings(record=True) as w:
warnings.filterwarnings('always', '', FutureWarning)
- assert_equal(insert(a, np.array([True]*4), 9), [1,9,9,9,9,2,3])
+ assert_equal(insert(a, np.array([True]*4), 9), [1, 9, 9, 9, 9, 2, 3])
assert_(w[0].category is FutureWarning)
def test_multidim(self):
a = [[1, 1, 1]]
r = [[2, 2, 2],
[1, 1, 1]]
- assert_equal(insert(a, 0, [1]), [1,1,1,1])
+ assert_equal(insert(a, 0, [1]), [1, 1, 1, 1])
assert_equal(insert(a, 0, [2, 2, 2], axis=0), r)
assert_equal(insert(a, 0, 2, axis=0), r)
assert_equal(insert(a, 2, 2, axis=1), [[1, 1, 2, 1]])
a = np.array([[1, 1], [2, 2], [3, 3]])
- b = np.arange(1,4).repeat(3).reshape(3,3)
- c = np.concatenate((a[:,0:1], np.arange(1,4).repeat(3).reshape(3,3).T,
- a[:,1:2]), axis=1)
- assert_equal(insert(a, [1], [[1],[2],[3]], axis=1), b)
+ b = np.arange(1, 4).repeat(3).reshape(3, 3)
+ c = np.concatenate((a[:, 0:1], np.arange(1, 4).repeat(3).reshape(3, 3).T,
+ a[:, 1:2]), axis=1)
+ assert_equal(insert(a, [1], [[1], [2], [3]], axis=1), b)
assert_equal(insert(a, [1], [1, 2, 3], axis=1), c)
# scalars behave differently, in this case exactly opposite:
assert_equal(insert(a, 1, [1, 2, 3], axis=1), b)
- assert_equal(insert(a, 1, [[1],[2],[3]], axis=1), c)
+ assert_equal(insert(a, 1, [[1], [2], [3]], axis=1), c)
- a = np.arange(4).reshape(2,2)
- assert_equal(insert(a[:,:1], 1, a[:,1], axis=1), a)
+ a = np.arange(4).reshape(2, 2)
+ assert_equal(insert(a[:, :1], 1, a[:, 1], axis=1), a)
assert_equal(insert(a[:1,:], 1, a[1,:], axis=0), a)
# negative axis value
- a = np.arange(24).reshape((2,3,4))
- assert_equal(insert(a, 1, a[:,:,3], axis=-1),
- insert(a, 1, a[:,:,3], axis=2))
- assert_equal(insert(a, 1, a[:,2,:], axis=-2),
- insert(a, 1, a[:,2,:], axis=1))
+ a = np.arange(24).reshape((2, 3, 4))
+ assert_equal(insert(a, 1, a[:,:, 3], axis=-1),
+ insert(a, 1, a[:,:, 3], axis=2))
+ assert_equal(insert(a, 1, a[:, 2,:], axis=-2),
+ insert(a, 1, a[:, 2,:], axis=1))
# invalid axis value
- assert_raises(IndexError, insert, a, 1, a[:,2,:], axis=3)
- assert_raises(IndexError, insert, a, 1, a[:,2,:], axis=-4)
+ assert_raises(IndexError, insert, a, 1, a[:, 2,:], axis=3)
+ assert_raises(IndexError, insert, a, 1, a[:, 2,:], axis=-4)
def test_0d(self):
# This is an error in the future
@@ -236,9 +236,9 @@ class TestInsert(TestCase):
a = np.arange(10).view(SubClass)
assert_(isinstance(np.insert(a, 0, [0]), SubClass))
assert_(isinstance(np.insert(a, [], []), SubClass))
- assert_(isinstance(np.insert(a, [0,1], [1,2]), SubClass))
- assert_(isinstance(np.insert(a, slice(1,2), [1,2]), SubClass))
- assert_(isinstance(np.insert(a, slice(1,-2), []), SubClass))
+ assert_(isinstance(np.insert(a, [0, 1], [1, 2]), SubClass))
+ assert_(isinstance(np.insert(a, slice(1, 2), [1, 2]), SubClass))
+ assert_(isinstance(np.insert(a, slice(1, -2), []), SubClass))
# This is an error in the future:
a = np.array(1).view(SubClass)
assert_(isinstance(np.insert(a, 0, [0]), SubClass))
@@ -355,10 +355,10 @@ class TestDiff(TestCase):
def test_nd(self):
x = 20 * rand(10, 20, 30)
- out1 = x[:, :, 1:] - x[:, :, :-1]
- out2 = out1[:, :, 1:] - out1[:, :, :-1]
- out3 = x[1:, :, :] - x[:-1, :, :]
- out4 = out3[1:, :, :] - out3[:-1, :, :]
+ out1 = x[:,:, 1:] - x[:,:, :-1]
+ out2 = out1[:,:, 1:] - out1[:,:, :-1]
+ out3 = x[1:,:,:] - x[:-1,:,:]
+ out4 = out3[1:,:,:] - out3[:-1,:,:]
assert_array_equal(diff(x), out1)
assert_array_equal(diff(x, n=2), out2)
assert_array_equal(diff(x, axis=0), out3)
@@ -368,7 +368,7 @@ class TestDiff(TestCase):
class TestDelete(TestCase):
def setUp(self):
self.a = np.arange(5)
- self.nd_a = np.arange(5).repeat(2).reshape(1,5,2)
+ self.nd_a = np.arange(5).repeat(2).reshape(1, 5, 2)
def _check_inverse_of_slicing(self, indices):
a_del = delete(self.a, indices)
@@ -380,8 +380,8 @@ class TestDelete(TestCase):
indices = indices[(indices >= 0) & (indices < 5)]
assert_array_equal(setxor1d(a_del, self.a[indices,]), self.a,
err_msg=msg)
- xor = setxor1d(nd_a_del[0,:,0], self.nd_a[0,indices,0])
- assert_array_equal(xor, self.nd_a[0,:,0], err_msg=msg)
+ xor = setxor1d(nd_a_del[0,:, 0], self.nd_a[0, indices, 0])
+ assert_array_equal(xor, self.nd_a[0,:, 0], err_msg=msg)
def test_slices(self):
lims = [-6, -2, 0, 1, 2, 4, 5]
@@ -394,7 +394,7 @@ class TestDelete(TestCase):
def test_fancy(self):
# Deprecation/FutureWarning tests should be kept after change.
- self._check_inverse_of_slicing(np.array([[0,1],[2,1]]))
+ self._check_inverse_of_slicing(np.array([[0, 1], [2, 1]]))
assert_raises(DeprecationWarning, delete, self.a, [100])
assert_raises(DeprecationWarning, delete, self.a, [-100])
with warnings.catch_warnings(record=True) as w:
@@ -422,9 +422,9 @@ class TestDelete(TestCase):
a = self.a.view(SubClass)
assert_(isinstance(delete(a, 0), SubClass))
assert_(isinstance(delete(a, []), SubClass))
- assert_(isinstance(delete(a, [0,1]), SubClass))
- assert_(isinstance(delete(a, slice(1,2)), SubClass))
- assert_(isinstance(delete(a, slice(1,-2)), SubClass))
+ assert_(isinstance(delete(a, [0, 1]), SubClass))
+ assert_(isinstance(delete(a, slice(1, 2)), SubClass))
+ assert_(isinstance(delete(a, slice(1, -2)), SubClass))
class TestGradient(TestCase):
def test_basic(self):
@@ -598,7 +598,7 @@ class TestVectorize(TestCase):
while _p:
res = res*x + _p.pop(0)
return res
- vpolyval = np.vectorize(mypolyval, excluded=['p',1])
+ vpolyval = np.vectorize(mypolyval, excluded=['p', 1])
ans = [3, 6]
assert_array_equal(ans, vpolyval(x=[0, 1], p=[1, 2, 3]))
assert_array_equal(ans, vpolyval([0, 1], p=[1, 2, 3]))
@@ -776,18 +776,18 @@ class TestTrapz(TestCase):
wz[0] /= 2
wz[-1] /= 2
- q = x[:, None, None] + y[None, :, None] + z[None, None, :]
+ q = x[:, None, None] + y[None,:, None] + z[None, None,:]
qx = (q * wx[:, None, None]).sum(axis=0)
- qy = (q * wy[None, :, None]).sum(axis=1)
- qz = (q * wz[None, None, :]).sum(axis=2)
+ qy = (q * wy[None,:, None]).sum(axis=1)
+ qz = (q * wz[None, None,:]).sum(axis=2)
# n-d `x`
r = trapz(q, x=x[:, None, None], axis=0)
assert_almost_equal(r, qx)
- r = trapz(q, x=y[None, :, None], axis=1)
+ r = trapz(q, x=y[None,:, None], axis=1)
assert_almost_equal(r, qy)
- r = trapz(q, x=z[None, None, :], axis=2)
+ r = trapz(q, x=z[None, None,:], axis=2)
assert_almost_equal(r, qz)
# 1-d `x`
@@ -1052,7 +1052,7 @@ class TestHistogramdd(TestCase):
def test_identical_samples(self):
x = np.zeros((10, 2), int)
hist, edges = histogramdd(x, bins=2)
- assert_array_equal(edges[0], np.array([-0.5, 0. , 0.5]))
+ assert_array_equal(edges[0], np.array([-0.5, 0., 0.5]))
def test_empty(self):
a, b = histogramdd([[], []], bins=([0, 1], [0, 1]))
@@ -1114,23 +1114,23 @@ class TestCheckFinite(TestCase):
class TestCorrCoef(TestCase):
A = np.array([[ 0.15391142, 0.18045767, 0.14197213],
[ 0.70461506, 0.96474128, 0.27906989],
- [ 0.9297531 , 0.32296769, 0.19267156]])
- B = np.array([[ 0.10377691, 0.5417086 , 0.49807457],
+ [ 0.9297531, 0.32296769, 0.19267156]])
+ B = np.array([[ 0.10377691, 0.5417086, 0.49807457],
[ 0.82872117, 0.77801674, 0.39226705],
- [ 0.9314666 , 0.66800209, 0.03538394]])
- res1 = np.array([[ 1. , 0.9379533 , -0.04931983],
- [ 0.9379533 , 1. , 0.30007991],
+ [ 0.9314666, 0.66800209, 0.03538394]])
+ res1 = np.array([[ 1., 0.9379533, -0.04931983],
+ [ 0.9379533, 1., 0.30007991],
[-0.04931983, 0.30007991, 1. ]])
- res2 = np.array([[ 1. , 0.9379533 , -0.04931983,
+ res2 = np.array([[ 1., 0.9379533, -0.04931983,
0.30151751, 0.66318558, 0.51532523],
- [ 0.9379533 , 1. , 0.30007991,
+ [ 0.9379533, 1., 0.30007991,
- 0.04781421, 0.88157256, 0.78052386],
- [-0.04931983, 0.30007991, 1. ,
+ [-0.04931983, 0.30007991, 1.,
- 0.96717111, 0.71483595, 0.83053601],
[ 0.30151751, -0.04781421, -0.96717111,
- 1. , -0.51366032, -0.66173113],
+ 1., -0.51366032, -0.66173113],
[ 0.66318558, 0.88157256, 0.71483595,
- - 0.51366032, 1. , 0.98317823],
+ - 0.51366032, 1., 0.98317823],
[ 0.51532523, 0.78052386, 0.83053601,
- 0.66173113, 0.98317823, 1. ]])
@@ -1160,10 +1160,10 @@ class TestCov(TestCase):
class Test_I0(TestCase):
def test_simple(self):
assert_almost_equal(i0(0.5), np.array(1.0634833707413234))
- A = np.array([ 0.49842636, 0.6969809 , 0.22011976, 0.0155549])
+ A = np.array([ 0.49842636, 0.6969809, 0.22011976, 0.0155549])
assert_almost_equal(i0(A),
np.array([ 1.06307822, 1.12518299, 1.01214991, 1.00006049]))
- B = np.array([[ 0.827002 , 0.99959078],
+ B = np.array([[ 0.827002, 0.99959078],
[ 0.89694769, 0.39298162],
[ 0.37954418, 0.05206293],
[ 0.36465447, 0.72446427],
@@ -1173,7 +1173,7 @@ class Test_I0(TestCase):
[ 1.21147086, 1.0389829 ],
[ 1.03633899, 1.00067775],
[ 1.03352052, 1.13557954],
- [ 1.0588429 , 1.06432317]]))
+ [ 1.0588429, 1.06432317]]))
class TestKaiser(TestCase):
@@ -1182,10 +1182,10 @@ class TestKaiser(TestCase):
assert_(np.isfinite(kaiser(1, 1.0)))
assert_almost_equal(kaiser(2, 1.0), np.array([ 0.78984831, 0.78984831]))
assert_almost_equal(kaiser(5, 1.0),
- np.array([ 0.78984831, 0.94503323, 1. ,
+ np.array([ 0.78984831, 0.94503323, 1.,
0.94503323, 0.78984831]))
assert_almost_equal(kaiser(5, 1.56789),
- np.array([ 0.58285404, 0.88409679, 1. ,
+ np.array([ 0.58285404, 0.88409679, 1.,
0.88409679, 0.58285404]))
def test_int_beta(self):
diff --git a/numpy/lib/tests/test_index_tricks.py b/numpy/lib/tests/test_index_tricks.py
index 32b3c7036..9002331ce 100644
--- a/numpy/lib/tests/test_index_tricks.py
+++ b/numpy/lib/tests/test_index_tricks.py
@@ -8,42 +8,42 @@ from numpy import ( array, ones, r_, mgrid, unravel_index, zeros, where,
class TestRavelUnravelIndex(TestCase):
def test_basic(self):
- assert_equal(np.unravel_index(2,(2,2)), (1,0))
- assert_equal(np.ravel_multi_index((1,0),(2,2)), 2)
- assert_equal(np.unravel_index(254,(17,94)), (2,66))
- assert_equal(np.ravel_multi_index((2,66),(17,94)), 254)
- assert_raises(ValueError, np.unravel_index, -1, (2,2))
- assert_raises(TypeError, np.unravel_index, 0.5, (2,2))
- assert_raises(ValueError, np.unravel_index, 4, (2,2))
- assert_raises(ValueError, np.ravel_multi_index, (-3,1), (2,2))
- assert_raises(ValueError, np.ravel_multi_index, (2,1), (2,2))
- assert_raises(ValueError, np.ravel_multi_index, (0,-3), (2,2))
- assert_raises(ValueError, np.ravel_multi_index, (0,2), (2,2))
- assert_raises(TypeError, np.ravel_multi_index, (0.1,0.), (2,2))
-
- assert_equal(np.unravel_index((2*3 + 1)*6 + 4, (4,3,6)), [2,1,4])
- assert_equal(np.ravel_multi_index([2,1,4], (4,3,6)), (2*3 + 1)*6 + 4)
-
- arr = np.array([[3,6,6],[4,5,1]])
- assert_equal(np.ravel_multi_index(arr, (7,6)), [22,41,37])
- assert_equal(np.ravel_multi_index(arr, (7,6), order='F'), [31,41,13])
- assert_equal(np.ravel_multi_index(arr, (4,6), mode='clip'), [22,23,19])
- assert_equal(np.ravel_multi_index(arr, (4,4), mode=('clip','wrap')),
- [12,13,13])
- assert_equal(np.ravel_multi_index((3,1,4,1), (6,7,8,9)), 1621)
-
- assert_equal(np.unravel_index(np.array([22, 41, 37]), (7,6)),
- [[3, 6, 6],[4, 5, 1]])
- assert_equal(np.unravel_index(np.array([31, 41, 13]), (7,6), order='F'),
+ assert_equal(np.unravel_index(2, (2, 2)), (1, 0))
+ assert_equal(np.ravel_multi_index((1, 0), (2, 2)), 2)
+ assert_equal(np.unravel_index(254, (17, 94)), (2, 66))
+ assert_equal(np.ravel_multi_index((2, 66), (17, 94)), 254)
+ assert_raises(ValueError, np.unravel_index, -1, (2, 2))
+ assert_raises(TypeError, np.unravel_index, 0.5, (2, 2))
+ assert_raises(ValueError, np.unravel_index, 4, (2, 2))
+ assert_raises(ValueError, np.ravel_multi_index, (-3, 1), (2, 2))
+ assert_raises(ValueError, np.ravel_multi_index, (2, 1), (2, 2))
+ assert_raises(ValueError, np.ravel_multi_index, (0, -3), (2, 2))
+ assert_raises(ValueError, np.ravel_multi_index, (0, 2), (2, 2))
+ assert_raises(TypeError, np.ravel_multi_index, (0.1, 0.), (2, 2))
+
+ assert_equal(np.unravel_index((2*3 + 1)*6 + 4, (4, 3, 6)), [2, 1, 4])
+ assert_equal(np.ravel_multi_index([2, 1, 4], (4, 3, 6)), (2*3 + 1)*6 + 4)
+
+ arr = np.array([[3, 6, 6], [4, 5, 1]])
+ assert_equal(np.ravel_multi_index(arr, (7, 6)), [22, 41, 37])
+ assert_equal(np.ravel_multi_index(arr, (7, 6), order='F'), [31, 41, 13])
+ assert_equal(np.ravel_multi_index(arr, (4, 6), mode='clip'), [22, 23, 19])
+ assert_equal(np.ravel_multi_index(arr, (4, 4), mode=('clip', 'wrap')),
+ [12, 13, 13])
+ assert_equal(np.ravel_multi_index((3, 1, 4, 1), (6, 7, 8, 9)), 1621)
+
+ assert_equal(np.unravel_index(np.array([22, 41, 37]), (7, 6)),
[[3, 6, 6], [4, 5, 1]])
- assert_equal(np.unravel_index(1621, (6,7,8,9)), [3,1,4,1])
+ assert_equal(np.unravel_index(np.array([31, 41, 13]), (7, 6), order='F'),
+ [[3, 6, 6], [4, 5, 1]])
+ assert_equal(np.unravel_index(1621, (6, 7, 8, 9)), [3, 1, 4, 1])
def test_dtypes(self):
# Test with different data types
for dtype in [np.int16, np.uint16, np.int32,
np.uint32, np.int64, np.uint64]:
- coords = np.array([[1,0,1,2,3,4],[1,6,1,3,2,0]], dtype=dtype)
- shape = (5,8)
+ coords = np.array([[1, 0, 1, 2, 3, 4], [1, 6, 1, 3, 2, 0]], dtype=dtype)
+ shape = (5, 8)
uncoords = 8*coords[0]+coords[1]
assert_equal(np.ravel_multi_index(coords, shape), uncoords)
assert_equal(coords, np.unravel_index(uncoords, shape))
@@ -51,9 +51,9 @@ class TestRavelUnravelIndex(TestCase):
assert_equal(np.ravel_multi_index(coords, shape, order='F'), uncoords)
assert_equal(coords, np.unravel_index(uncoords, shape, order='F'))
- coords = np.array([[1,0,1,2,3,4],[1,6,1,3,2,0],[1,3,1,0,9,5]],
+ coords = np.array([[1, 0, 1, 2, 3, 4], [1, 6, 1, 3, 2, 0], [1, 3, 1, 0, 9, 5]],
dtype=dtype)
- shape = (5,8,10)
+ shape = (5, 8, 10)
uncoords = 10*(8*coords[0]+coords[1])+coords[2]
assert_equal(np.ravel_multi_index(coords, shape), uncoords)
assert_equal(coords, np.unravel_index(uncoords, shape))
@@ -63,12 +63,12 @@ class TestRavelUnravelIndex(TestCase):
def test_clipmodes(self):
# Test clipmodes
- assert_equal(np.ravel_multi_index([5,1,-1,2], (4,3,7,12), mode='wrap'),
- np.ravel_multi_index([1,1,6,2], (4,3,7,12)))
- assert_equal(np.ravel_multi_index([5,1,-1,2], (4,3,7,12),
- mode=('wrap','raise','clip','raise')),
- np.ravel_multi_index([1,1,0,2], (4,3,7,12)))
- assert_raises(ValueError, np.ravel_multi_index, [5,1,-1,2], (4,3,7,12))
+ assert_equal(np.ravel_multi_index([5, 1, -1, 2], (4, 3, 7, 12), mode='wrap'),
+ np.ravel_multi_index([1, 1, 6, 2], (4, 3, 7, 12)))
+ assert_equal(np.ravel_multi_index([5, 1, -1, 2], (4, 3, 7, 12),
+ mode=('wrap', 'raise', 'clip', 'raise')),
+ np.ravel_multi_index([1, 1, 0, 2], (4, 3, 7, 12)))
+ assert_raises(ValueError, np.ravel_multi_index, [5, 1, -1, 2], (4, 3, 7, 12))
class TestGrid(TestCase):
def test_basic(self):
@@ -77,63 +77,63 @@ class TestGrid(TestCase):
assert_(a.shape == (10,))
assert_(b.shape == (20,))
assert_(a[0] == -1)
- assert_almost_equal(a[-1],1)
+ assert_almost_equal(a[-1], 1)
assert_(b[0] == -1)
- assert_almost_equal(b[1]-b[0],0.1,11)
- assert_almost_equal(b[-1],b[0]+19*0.1,11)
- assert_almost_equal(a[1]-a[0],2.0/9.0,11)
+ assert_almost_equal(b[1]-b[0], 0.1, 11)
+ assert_almost_equal(b[-1], b[0]+19*0.1, 11)
+ assert_almost_equal(a[1]-a[0], 2.0/9.0, 11)
def test_linspace_equivalence(self):
- y,st = np.linspace(2,10,retstep=1)
- assert_almost_equal(st,8/49.0)
- assert_array_almost_equal(y,mgrid[2:10:50j],13)
+ y, st = np.linspace(2, 10, retstep=1)
+ assert_almost_equal(st, 8/49.0)
+ assert_array_almost_equal(y, mgrid[2:10:50j], 13)
def test_nd(self):
- c = mgrid[-1:1:10j,-2:2:10j]
- d = mgrid[-1:1:0.1,-2:2:0.2]
- assert_(c.shape == (2,10,10))
- assert_(d.shape == (2,20,20))
- assert_array_equal(c[0][0,:],-ones(10,'d'))
- assert_array_equal(c[1][:,0],-2*ones(10,'d'))
- assert_array_almost_equal(c[0][-1,:],ones(10,'d'),11)
- assert_array_almost_equal(c[1][:,-1],2*ones(10,'d'),11)
- assert_array_almost_equal(d[0,1,:]-d[0,0,:], 0.1*ones(20,'d'),11)
- assert_array_almost_equal(d[1,:,1]-d[1,:,0], 0.2*ones(20,'d'),11)
+ c = mgrid[-1:1:10j, -2:2:10j]
+ d = mgrid[-1:1:0.1, -2:2:0.2]
+ assert_(c.shape == (2, 10, 10))
+ assert_(d.shape == (2, 20, 20))
+ assert_array_equal(c[0][0,:], -ones(10, 'd'))
+ assert_array_equal(c[1][:, 0], -2*ones(10, 'd'))
+ assert_array_almost_equal(c[0][-1,:], ones(10, 'd'), 11)
+ assert_array_almost_equal(c[1][:, -1], 2*ones(10, 'd'), 11)
+ assert_array_almost_equal(d[0, 1,:]-d[0, 0,:], 0.1*ones(20, 'd'), 11)
+ assert_array_almost_equal(d[1,:, 1]-d[1,:, 0], 0.2*ones(20, 'd'), 11)
class TestConcatenator(TestCase):
def test_1d(self):
- assert_array_equal(r_[1,2,3,4,5,6],array([1,2,3,4,5,6]))
+ assert_array_equal(r_[1, 2, 3, 4, 5, 6], array([1, 2, 3, 4, 5, 6]))
b = ones(5)
- c = r_[b,0,0,b]
- assert_array_equal(c,[1,1,1,1,1,0,0,1,1,1,1,1])
+ c = r_[b, 0, 0, b]
+ assert_array_equal(c, [1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1])
def test_mixed_type(self):
g = r_[10.1, 1:10]
assert_(g.dtype == 'f8')
def test_more_mixed_type(self):
- g = r_[-10.1, array([1]), array([2,3,4]), 10.0]
+ g = r_[-10.1, array([1]), array([2, 3, 4]), 10.0]
assert_(g.dtype == 'f8')
def test_2d(self):
- b = rand(5,5)
- c = rand(5,5)
- d = r_['1',b,c] # append columns
- assert_(d.shape == (5,10))
- assert_array_equal(d[:,:5],b)
- assert_array_equal(d[:,5:],c)
- d = r_[b,c]
- assert_(d.shape == (10,5))
- assert_array_equal(d[:5,:],b)
- assert_array_equal(d[5:,:],c)
+ b = rand(5, 5)
+ c = rand(5, 5)
+ d = r_['1', b, c] # append columns
+ assert_(d.shape == (5, 10))
+ assert_array_equal(d[:, :5], b)
+ assert_array_equal(d[:, 5:], c)
+ d = r_[b, c]
+ assert_(d.shape == (10, 5))
+ assert_array_equal(d[:5,:], b)
+ assert_array_equal(d[5:,:], c)
class TestNdenumerate(TestCase):
def test_basic(self):
- a = array([[1,2], [3,4]])
+ a = array([[1, 2], [3, 4]])
assert_equal(list(ndenumerate(a)),
- [((0,0), 1), ((0,1), 2), ((1,0), 3), ((1,1), 4)])
+ [((0, 0), 1), ((0, 1), 2), ((1, 0), 3), ((1, 1), 4)])
class TestIndexExpression(TestCase):
@@ -144,17 +144,17 @@ class TestIndexExpression(TestCase):
assert_equal(a[:-1], a[index_exp[:-1]])
def test_simple_1(self):
- a = np.random.rand(4,5,6)
+ a = np.random.rand(4, 5, 6)
- assert_equal(a[:,:3,[1,2]], a[index_exp[:,:3,[1,2]]])
- assert_equal(a[:,:3,[1,2]], a[s_[:,:3,[1,2]]])
+ assert_equal(a[:, :3, [1, 2]], a[index_exp[:, :3, [1, 2]]])
+ assert_equal(a[:, :3, [1, 2]], a[s_[:, :3, [1, 2]]])
def test_c_():
- a = np.c_[np.array([[1,2,3]]), 0, 0, np.array([[4,5,6]])]
+ a = np.c_[np.array([[1, 2, 3]]), 0, 0, np.array([[4, 5, 6]])]
assert_equal(a, [[1, 2, 3, 0, 0, 4, 5, 6]])
def test_fill_diagonal():
- a = zeros((3, 3),int)
+ a = zeros((3, 3), int)
fill_diagonal(a, 5)
yield (assert_array_equal, a,
array([[5, 0, 0],
@@ -162,7 +162,7 @@ def test_fill_diagonal():
[0, 0, 5]]))
#Test tall matrix
- a = zeros((10, 3),int)
+ a = zeros((10, 3), int)
fill_diagonal(a, 5)
yield (assert_array_equal, a,
array([[5, 0, 0],
@@ -177,7 +177,7 @@ def test_fill_diagonal():
[0, 0, 0]]))
#Test tall matrix wrap
- a = zeros((10, 3),int)
+ a = zeros((10, 3), int)
fill_diagonal(a, 5, True)
yield (assert_array_equal, a,
array([[5, 0, 0],
@@ -192,7 +192,7 @@ def test_fill_diagonal():
[0, 5, 0]]))
#Test wide matrix
- a = zeros((3, 10),int)
+ a = zeros((3, 10), int)
fill_diagonal(a, 5)
yield (assert_array_equal, a,
array([[5, 0, 0, 0, 0, 0, 0, 0, 0, 0],
@@ -223,7 +223,7 @@ def test_diag_indices():
d3 = diag_indices(2, 3)
# And use it to set the diagonal of a zeros array to 1:
- a = zeros((2, 2, 2),int)
+ a = zeros((2, 2, 2), int)
a[d3] = 1
yield (assert_array_equal, a,
array([[[1, 0],
@@ -256,7 +256,7 @@ def test_ndindex():
assert_equal(x, [()])
x = list(np.ndindex(()))
- assert_equal(x, [()])
+ assert_equal(x, [()])
if __name__ == "__main__":
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 4095dd813..af06cd45e 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -583,7 +583,7 @@ class TestLoadTxt(TestCase):
('block', int, (2, 2, 3))])
x = np.loadtxt(c, dtype=dt)
a = np.array([('aaaa', 1.0, 8.0,
- [[[1, 2, 3], [4, 5, 6]],[[7, 8, 9], [10, 11, 12]]])],
+ [[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]])],
dtype=dt)
assert_array_equal(x, a)
@@ -1554,7 +1554,7 @@ M 33 21.99
def test_gft_using_filename(self):
# Test that we can load data from a filename as well as a file object
- wanted = np.arange(6).reshape((2,3))
+ wanted = np.arange(6).reshape((2, 3))
if sys.version_info[0] >= 3:
# python 3k is known to fail for '\r'
linesep = ('\n', '\r\n')
diff --git a/numpy/lib/tests/test_nanfunctions.py b/numpy/lib/tests/test_nanfunctions.py
index 93a5ef855..292ffdf7a 100644
--- a/numpy/lib/tests/test_nanfunctions.py
+++ b/numpy/lib/tests/test_nanfunctions.py
@@ -17,7 +17,7 @@ _ndat = np.array(
[[ 0.6244, np.nan, 0.2692, 0.0116, np.nan, 0.1170],
[ 0.5351, 0.9403, np.nan, 0.2100, 0.4759, 0.2833],
[ np.nan, np.nan, np.nan, 0.1042, np.nan, 0.5954],
- [ 0.161 , np.nan, np.nan, 0.1859, 0.3146, np.nan]]
+ [ 0.161, np.nan, np.nan, 0.1859, 0.3146, np.nan]]
)
# rows of _ndat with nans removed
@@ -131,7 +131,7 @@ class TestNanFunctions_ArgminArgmax(TestCase):
assert_(issubclass(w[0].category, NanWarning))
def test_empty(self):
- mat = np.zeros((0,3))
+ mat = np.zeros((0, 3))
for f in self.nanfuncs:
for axis in [0, None]:
assert_raises(ValueError, f, mat, axis=axis)
@@ -253,7 +253,7 @@ class TestNanFunctions_Sum(TestCase):
assert_(len(w) == 0, 'warning raised')
def test_empty(self):
- mat = np.zeros((0,3))
+ mat = np.zeros((0, 3))
if np.__version__[:3] < '1.9':
tgt = [np.nan]*3
res = nansum(mat, axis=0)
@@ -398,7 +398,7 @@ class TestNanFunctions_MeanVarStd(TestCase):
assert_(issubclass(w[0].category, NanWarning))
def test_empty(self):
- mat = np.zeros((0,3))
+ mat = np.zeros((0, 3))
for f in self.nanfuncs:
for axis in [0, None]:
with warnings.catch_warnings(record=True) as w:
diff --git a/numpy/lib/tests/test_polynomial.py b/numpy/lib/tests/test_polynomial.py
index fa166b7f1..617419eee 100644
--- a/numpy/lib/tests/test_polynomial.py
+++ b/numpy/lib/tests/test_polynomial.py
@@ -86,29 +86,29 @@ class TestDocs(TestCase):
return rundocs()
def test_roots(self):
- assert_array_equal(np.roots([1,0,0]), [0,0])
+ assert_array_equal(np.roots([1, 0, 0]), [0, 0])
def test_str_leading_zeros(self):
- p = np.poly1d([4,3,2,1])
+ p = np.poly1d([4, 3, 2, 1])
p[3] = 0
assert_equal(str(p),
" 2\n"
"3 x + 2 x + 1")
- p = np.poly1d([1,2])
+ p = np.poly1d([1, 2])
p[0] = 0
p[1] = 0
assert_equal(str(p), " \n0")
def test_polyfit(self) :
c = np.array([3., 2., 1.])
- x = np.linspace(0,2,7)
- y = np.polyval(c,x)
- err = [1,-1,1,-1,1,-1,1]
- weights = np.arange(8,1,-1)**2/7.0
+ x = np.linspace(0, 2, 7)
+ y = np.polyval(c, x)
+ err = [1, -1, 1, -1, 1, -1, 1]
+ weights = np.arange(8, 1, -1)**2/7.0
# check 1D case
- m, cov = np.polyfit(x,y+err,2,cov=True)
+ m, cov = np.polyfit(x, y+err, 2, cov=True)
est = [3.8571, 0.2857, 1.619]
assert_almost_equal(est, m, decimal=4)
val0 = [[2.9388, -5.8776, 1.6327],
@@ -116,7 +116,7 @@ class TestDocs(TestCase):
[1.6327, -4.2449, 2.3220]]
assert_almost_equal(val0, cov, decimal=4)
- m2, cov2 = np.polyfit(x,y+err,2,w=weights,cov=True)
+ m2, cov2 = np.polyfit(x, y+err, 2, w=weights, cov=True)
assert_almost_equal([4.8927, -1.0177, 1.7768], m2, decimal=4)
val = [[ 8.7929, -10.0103, 0.9756],
[-10.0103, 13.6134, -1.8178],
@@ -124,19 +124,19 @@ class TestDocs(TestCase):
assert_almost_equal(val, cov2, decimal=4)
# check 2D (n,1) case
- y = y[:,np.newaxis]
- c = c[:,np.newaxis]
- assert_almost_equal(c, np.polyfit(x,y,2))
+ y = y[:, np.newaxis]
+ c = c[:, np.newaxis]
+ assert_almost_equal(c, np.polyfit(x, y, 2))
# check 2D (n,2) case
- yy = np.concatenate((y,y), axis=1)
- cc = np.concatenate((c,c), axis=1)
- assert_almost_equal(cc, np.polyfit(x,yy,2))
+ yy = np.concatenate((y, y), axis=1)
+ cc = np.concatenate((c, c), axis=1)
+ assert_almost_equal(cc, np.polyfit(x, yy, 2))
- m, cov = np.polyfit(x,yy + np.array(err)[:,np.newaxis],2,cov=True)
- assert_almost_equal(est, m[:,0], decimal=4)
- assert_almost_equal(est, m[:,1], decimal=4)
- assert_almost_equal(val0, cov[:,:,0], decimal=4)
- assert_almost_equal(val0, cov[:,:,1], decimal=4)
+ m, cov = np.polyfit(x, yy + np.array(err)[:, np.newaxis], 2, cov=True)
+ assert_almost_equal(est, m[:, 0], decimal=4)
+ assert_almost_equal(est, m[:, 1], decimal=4)
+ assert_almost_equal(val0, cov[:,:, 0], decimal=4)
+ assert_almost_equal(val0, cov[:,:, 1], decimal=4)
def test_objects(self):
from decimal import Decimal
@@ -153,14 +153,14 @@ class TestDocs(TestCase):
def test_complex(self):
p = np.poly1d([3j, 2j, 1j])
p2 = p.integ()
- assert_((p2.coeffs == [1j,1j,1j,0]).all())
+ assert_((p2.coeffs == [1j, 1j, 1j, 0]).all())
p2 = p.deriv()
- assert_((p2.coeffs == [6j,2j]).all())
+ assert_((p2.coeffs == [6j, 2j]).all())
def test_integ_coeffs(self):
- p = np.poly1d([3,2,1])
- p2 = p.integ(3, k=[9,7,6])
- assert_((p2.coeffs == [1/4./5.,1/3./4.,1/2./3.,9/1./2.,7,6]).all())
+ p = np.poly1d([3, 2, 1])
+ p2 = p.integ(3, k=[9, 7, 6])
+ assert_((p2.coeffs == [1/4./5., 1/3./4., 1/2./3., 9/1./2., 7, 6]).all())
def test_zero_dims(self):
try:
diff --git a/numpy/lib/tests/test_recfunctions.py b/numpy/lib/tests/test_recfunctions.py
index ef22ca413..b175bcb64 100644
--- a/numpy/lib/tests/test_recfunctions.py
+++ b/numpy/lib/tests/test_recfunctions.py
@@ -660,13 +660,13 @@ class TestJoinBy2(TestCase):
assert_equal(test, control)
def test_two_keys_two_vars(self):
- a = np.array(list(zip(np.tile([10,11],5),np.repeat(np.arange(5),2),
- np.arange(50, 60), np.arange(10,20))),
- dtype=[('k', int), ('a', int), ('b', int),('c',int)])
+ a = np.array(list(zip(np.tile([10, 11], 5), np.repeat(np.arange(5), 2),
+ np.arange(50, 60), np.arange(10, 20))),
+ dtype=[('k', int), ('a', int), ('b', int), ('c', int)])
- b = np.array(list(zip(np.tile([10,11],5),np.repeat(np.arange(5),2),
- np.arange(65, 75), np.arange(0,10))),
- dtype=[('k', int), ('a', int), ('b', int), ('c',int)])
+ b = np.array(list(zip(np.tile([10, 11], 5), np.repeat(np.arange(5), 2),
+ np.arange(65, 75), np.arange(0, 10))),
+ dtype=[('k', int), ('a', int), ('b', int), ('c', int)])
control = np.array([(10, 0, 50, 65, 10, 0), (11, 0, 51, 66, 11, 1),
(10, 1, 52, 67, 12, 2), (11, 1, 53, 68, 13, 3),
@@ -675,7 +675,7 @@ class TestJoinBy2(TestCase):
(10, 4, 58, 73, 18, 8), (11, 4, 59, 74, 19, 9)],
dtype=[('k', int), ('a', int), ('b1', int),
('b2', int), ('c1', int), ('c2', int)])
- test = join_by(['a','k'], a, b, r1postfix='1', r2postfix='2', jointype='inner')
+ test = join_by(['a', 'k'], a, b, r1postfix='1', r2postfix='2', jointype='inner')
assert_equal(test.dtype, control.dtype)
assert_equal(test, control)
diff --git a/numpy/lib/tests/test_regression.py b/numpy/lib/tests/test_regression.py
index 1e9bacdf5..67808bd39 100644
--- a/numpy/lib/tests/test_regression.py
+++ b/numpy/lib/tests/test_regression.py
@@ -12,22 +12,22 @@ rlevel = 1
class TestRegression(TestCase):
def test_poly1d(self,level=rlevel):
"""Ticket #28"""
- assert_equal(np.poly1d([1]) - np.poly1d([1,0]),
- np.poly1d([-1,1]))
+ assert_equal(np.poly1d([1]) - np.poly1d([1, 0]),
+ np.poly1d([-1, 1]))
def test_cov_parameters(self,level=rlevel):
"""Ticket #91"""
- x = np.random.random((3,3))
+ x = np.random.random((3, 3))
y = x.copy()
np.cov(x, rowvar=1)
np.cov(y, rowvar=0)
- assert_array_equal(x,y)
+ assert_array_equal(x, y)
def test_mem_digitize(self,level=rlevel):
"""Ticket #95"""
for i in range(100):
- np.digitize([1,2,3,4],[1,3])
- np.digitize([0,1,2,3,4],[1,3])
+ np.digitize([1, 2, 3, 4], [1, 3])
+ np.digitize([0, 1, 2, 3, 4], [1, 3])
def test_unique_zero_sized(self,level=rlevel):
"""Ticket #205"""
@@ -36,51 +36,51 @@ class TestRegression(TestCase):
def test_mem_vectorise(self, level=rlevel):
"""Ticket #325"""
vt = np.vectorize(lambda *args: args)
- vt(np.zeros((1,2,1)), np.zeros((2,1,1)), np.zeros((1,1,2)))
- vt(np.zeros((1,2,1)), np.zeros((2,1,1)), np.zeros((1,1,2)), np.zeros((2,2)))
+ vt(np.zeros((1, 2, 1)), np.zeros((2, 1, 1)), np.zeros((1, 1, 2)))
+ vt(np.zeros((1, 2, 1)), np.zeros((2, 1, 1)), np.zeros((1, 1, 2)), np.zeros((2, 2)))
def test_mgrid_single_element(self, level=rlevel):
"""Ticket #339"""
- assert_array_equal(np.mgrid[0:0:1j],[0])
- assert_array_equal(np.mgrid[0:0],[])
+ assert_array_equal(np.mgrid[0:0:1j], [0])
+ assert_array_equal(np.mgrid[0:0], [])
def test_refcount_vectorize(self, level=rlevel):
"""Ticket #378"""
- def p(x,y): return 123
+ def p(x, y): return 123
v = np.vectorize(p)
_assert_valid_refcount(v)
def test_poly1d_nan_roots(self, level=rlevel):
"""Ticket #396"""
- p = np.poly1d([np.nan,np.nan,1], r=0)
- self.assertRaises(np.linalg.LinAlgError,getattr,p,"r")
+ p = np.poly1d([np.nan, np.nan, 1], r=0)
+ self.assertRaises(np.linalg.LinAlgError, getattr, p, "r")
def test_mem_polymul(self, level=rlevel):
"""Ticket #448"""
- np.polymul([],[1.])
+ np.polymul([], [1.])
def test_mem_string_concat(self, level=rlevel):
"""Ticket #469"""
x = np.array([])
- np.append(x,'asdasd\tasdasd')
+ np.append(x, 'asdasd\tasdasd')
def test_poly_div(self, level=rlevel):
"""Ticket #553"""
- u = np.poly1d([1,2,3])
- v = np.poly1d([1,2,3,4,5])
- q,r = np.polydiv(u,v)
+ u = np.poly1d([1, 2, 3])
+ v = np.poly1d([1, 2, 3, 4, 5])
+ q, r = np.polydiv(u, v)
assert_equal(q*v + r, u)
def test_poly_eq(self, level=rlevel):
"""Ticket #554"""
- x = np.poly1d([1,2,3])
- y = np.poly1d([3,4])
+ x = np.poly1d([1, 2, 3])
+ y = np.poly1d([3, 4])
assert_(x != y)
assert_(x == x)
def test_mem_insert(self, level=rlevel):
"""Ticket #572"""
- np.lib.place(1,1,1)
+ np.lib.place(1, 1, 1)
def test_polyfit_build(self):
"""Ticket #628"""
@@ -108,16 +108,16 @@ class TestRegression(TestCase):
"""Make polydiv work for complex types"""
msg = "Wrong type, should be complex"
x = np.ones(3, dtype=np.complex)
- q,r = np.polydiv(x,x)
+ q, r = np.polydiv(x, x)
assert_(q.dtype == np.complex, msg)
msg = "Wrong type, should be float"
x = np.ones(3, dtype=np.int)
- q,r = np.polydiv(x,x)
+ q, r = np.polydiv(x, x)
assert_(q.dtype == np.float, msg)
def test_histogramdd_too_many_bins(self) :
"""Ticket 928."""
- assert_raises(ValueError, np.histogramdd, np.ones((1,10)), bins=2**10)
+ assert_raises(ValueError, np.histogramdd, np.ones((1, 10)), bins=2**10)
def test_polyint_type(self) :
"""Ticket #944"""
@@ -144,20 +144,20 @@ class TestRegression(TestCase):
def dp():
n = 3
a = np.ones((n,)*5)
- i = np.random.randint(0,n,size=thesize)
- a[np.ix_(i,i,i,i,i)] = 0
+ i = np.random.randint(0, n, size=thesize)
+ a[np.ix_(i, i, i, i, i)] = 0
def dp2():
n = 3
a = np.ones((n,)*5)
- i = np.random.randint(0,n,size=thesize)
- g = a[np.ix_(i,i,i,i,i)]
+ i = np.random.randint(0, n, size=thesize)
+ g = a[np.ix_(i, i, i, i, i)]
self.assertRaises(ValueError, dp)
self.assertRaises(ValueError, dp2)
def test_void_coercion(self, level=rlevel):
- dt = np.dtype([('a','f4'),('b','i4')])
- x = np.zeros((1,),dt)
- assert_(np.r_[x,x].dtype == dt)
+ dt = np.dtype([('a', 'f4'), ('b', 'i4')])
+ x = np.zeros((1,), dt)
+ assert_(np.r_[x, x].dtype == dt)
def test_who_with_0dim_array(self, level=rlevel) :
"""ticket #1243"""
@@ -194,9 +194,9 @@ class TestRegression(TestCase):
"""Ticket #1676"""
from numpy.lib.recfunctions import append_fields
F = False
- base = np.array([1,2,3], dtype=np.int32)
+ base = np.array([1, 2, 3], dtype=np.int32)
data = np.eye(3).astype(np.int32)
- names = ['a','b','c']
+ names = ['a', 'b', 'c']
dlist = [np.float64, np.int32, np.int32]
try:
a = append_fields(base, names, data, dlist)
@@ -214,17 +214,17 @@ class TestRegression(TestCase):
x = np.loadtxt(StringIO("0 1 2 3"), dtype=dt)
assert_equal(x, np.array([((0, 1), (2, 3))], dtype=dt))
- dt = [("a", [("a", 'u1', (1,3)), ("b", 'u1')])]
+ dt = [("a", [("a", 'u1', (1, 3)), ("b", 'u1')])]
x = np.loadtxt(StringIO("0 1 2 3"), dtype=dt)
- assert_equal(x, np.array([(((0,1,2), 3),)], dtype=dt))
+ assert_equal(x, np.array([(((0, 1, 2), 3),)], dtype=dt))
- dt = [("a", 'u1', (2,2))]
+ dt = [("a", 'u1', (2, 2))]
x = np.loadtxt(StringIO("0 1 2 3"), dtype=dt)
assert_equal(x, np.array([(((0, 1), (2, 3)),)], dtype=dt))
- dt = [("a", 'u1', (2,3,2))]
+ dt = [("a", 'u1', (2, 3, 2))]
x = np.loadtxt(StringIO("0 1 2 3 4 5 6 7 8 9 10 11"), dtype=dt)
- data = [((((0,1), (2,3), (4,5)), ((6,7), (8,9), (10,11))),)]
+ data = [((((0, 1), (2, 3), (4, 5)), ((6, 7), (8, 9), (10, 11))),)]
assert_equal(x, np.array(data, dtype=dt))
def test_nansum_with_boolean(self):
diff --git a/numpy/lib/tests/test_shape_base.py b/numpy/lib/tests/test_shape_base.py
index a92ddde83..157e1beb3 100644
--- a/numpy/lib/tests/test_shape_base.py
+++ b/numpy/lib/tests/test_shape_base.py
@@ -7,133 +7,133 @@ from numpy import matrix, asmatrix
class TestApplyAlongAxis(TestCase):
def test_simple(self):
- a = ones((20,10),'d')
- assert_array_equal(apply_along_axis(len,0,a),len(a)*ones(shape(a)[1]))
+ a = ones((20, 10), 'd')
+ assert_array_equal(apply_along_axis(len, 0, a), len(a)*ones(shape(a)[1]))
def test_simple101(self,level=11):
- a = ones((10,101),'d')
- assert_array_equal(apply_along_axis(len,0,a),len(a)*ones(shape(a)[1]))
+ a = ones((10, 101), 'd')
+ assert_array_equal(apply_along_axis(len, 0, a), len(a)*ones(shape(a)[1]))
def test_3d(self):
- a = arange(27).reshape((3,3,3))
- assert_array_equal(apply_along_axis(sum,0,a),
- [[27,30,33],[36,39,42],[45,48,51]])
+ a = arange(27).reshape((3, 3, 3))
+ assert_array_equal(apply_along_axis(sum, 0, a),
+ [[27, 30, 33], [36, 39, 42], [45, 48, 51]])
class TestApplyOverAxes(TestCase):
def test_simple(self):
- a = arange(24).reshape(2,3,4)
- aoa_a = apply_over_axes(sum, a, [0,2])
- assert_array_equal(aoa_a, array([[[60],[92],[124]]]))
+ a = arange(24).reshape(2, 3, 4)
+ aoa_a = apply_over_axes(sum, a, [0, 2])
+ assert_array_equal(aoa_a, array([[[60], [92], [124]]]))
class TestArraySplit(TestCase):
def test_integer_0_split(self):
a = arange(10)
try:
- res = array_split(a,0)
+ res = array_split(a, 0)
assert_(0) # it should have thrown a value error
except ValueError:
pass
def test_integer_split(self):
a = arange(10)
- res = array_split(a,1)
+ res = array_split(a, 1)
desired = [arange(10)]
- compare_results(res,desired)
-
- res = array_split(a,2)
- desired = [arange(5),arange(5,10)]
- compare_results(res,desired)
-
- res = array_split(a,3)
- desired = [arange(4),arange(4,7),arange(7,10)]
- compare_results(res,desired)
-
- res = array_split(a,4)
- desired = [arange(3),arange(3,6),arange(6,8),arange(8,10)]
- compare_results(res,desired)
-
- res = array_split(a,5)
- desired = [arange(2),arange(2,4),arange(4,6),arange(6,8),arange(8,10)]
- compare_results(res,desired)
-
- res = array_split(a,6)
- desired = [arange(2),arange(2,4),arange(4,6),arange(6,8),arange(8,9),
- arange(9,10)]
- compare_results(res,desired)
-
- res = array_split(a,7)
- desired = [arange(2),arange(2,4),arange(4,6),arange(6,7),arange(7,8),
- arange(8,9), arange(9,10)]
- compare_results(res,desired)
-
- res = array_split(a,8)
- desired = [arange(2),arange(2,4),arange(4,5),arange(5,6),arange(6,7),
- arange(7,8), arange(8,9), arange(9,10)]
- compare_results(res,desired)
-
- res = array_split(a,9)
- desired = [arange(2),arange(2,3),arange(3,4),arange(4,5),arange(5,6),
- arange(6,7), arange(7,8), arange(8,9), arange(9,10)]
- compare_results(res,desired)
-
- res = array_split(a,10)
- desired = [arange(1),arange(1,2),arange(2,3),arange(3,4),
- arange(4,5),arange(5,6), arange(6,7), arange(7,8),
- arange(8,9), arange(9,10)]
- compare_results(res,desired)
-
- res = array_split(a,11)
- desired = [arange(1),arange(1,2),arange(2,3),arange(3,4),
- arange(4,5),arange(5,6), arange(6,7), arange(7,8),
- arange(8,9), arange(9,10),array([])]
- compare_results(res,desired)
+ compare_results(res, desired)
+
+ res = array_split(a, 2)
+ desired = [arange(5), arange(5, 10)]
+ compare_results(res, desired)
+
+ res = array_split(a, 3)
+ desired = [arange(4), arange(4, 7), arange(7, 10)]
+ compare_results(res, desired)
+
+ res = array_split(a, 4)
+ desired = [arange(3), arange(3, 6), arange(6, 8), arange(8, 10)]
+ compare_results(res, desired)
+
+ res = array_split(a, 5)
+ desired = [arange(2), arange(2, 4), arange(4, 6), arange(6, 8), arange(8, 10)]
+ compare_results(res, desired)
+
+ res = array_split(a, 6)
+ desired = [arange(2), arange(2, 4), arange(4, 6), arange(6, 8), arange(8, 9),
+ arange(9, 10)]
+ compare_results(res, desired)
+
+ res = array_split(a, 7)
+ desired = [arange(2), arange(2, 4), arange(4, 6), arange(6, 7), arange(7, 8),
+ arange(8, 9), arange(9, 10)]
+ compare_results(res, desired)
+
+ res = array_split(a, 8)
+ desired = [arange(2), arange(2, 4), arange(4, 5), arange(5, 6), arange(6, 7),
+ arange(7, 8), arange(8, 9), arange(9, 10)]
+ compare_results(res, desired)
+
+ res = array_split(a, 9)
+ desired = [arange(2), arange(2, 3), arange(3, 4), arange(4, 5), arange(5, 6),
+ arange(6, 7), arange(7, 8), arange(8, 9), arange(9, 10)]
+ compare_results(res, desired)
+
+ res = array_split(a, 10)
+ desired = [arange(1), arange(1, 2), arange(2, 3), arange(3, 4),
+ arange(4, 5), arange(5, 6), arange(6, 7), arange(7, 8),
+ arange(8, 9), arange(9, 10)]
+ compare_results(res, desired)
+
+ res = array_split(a, 11)
+ desired = [arange(1), arange(1, 2), arange(2, 3), arange(3, 4),
+ arange(4, 5), arange(5, 6), arange(6, 7), arange(7, 8),
+ arange(8, 9), arange(9, 10), array([])]
+ compare_results(res, desired)
def test_integer_split_2D_rows(self):
- a = array([arange(10),arange(10)])
- res = array_split(a,3,axis=0)
- desired = [array([arange(10)]),array([arange(10)]),array([])]
- compare_results(res,desired)
+ a = array([arange(10), arange(10)])
+ res = array_split(a, 3, axis=0)
+ desired = [array([arange(10)]), array([arange(10)]), array([])]
+ compare_results(res, desired)
def test_integer_split_2D_cols(self):
- a = array([arange(10),arange(10)])
- res = array_split(a,3,axis=-1)
- desired = [array([arange(4),arange(4)]),
- array([arange(4,7),arange(4,7)]),
- array([arange(7,10),arange(7,10)])]
- compare_results(res,desired)
+ a = array([arange(10), arange(10)])
+ res = array_split(a, 3, axis=-1)
+ desired = [array([arange(4), arange(4)]),
+ array([arange(4, 7), arange(4, 7)]),
+ array([arange(7, 10), arange(7, 10)])]
+ compare_results(res, desired)
def test_integer_split_2D_default(self):
""" This will fail if we change default axis
"""
- a = array([arange(10),arange(10)])
- res = array_split(a,3)
- desired = [array([arange(10)]),array([arange(10)]),array([])]
- compare_results(res,desired)
+ a = array([arange(10), arange(10)])
+ res = array_split(a, 3)
+ desired = [array([arange(10)]), array([arange(10)]), array([])]
+ compare_results(res, desired)
#perhaps should check higher dimensions
def test_index_split_simple(self):
a = arange(10)
- indices = [1,5,7]
- res = array_split(a,indices,axis=-1)
- desired = [arange(0,1),arange(1,5),arange(5,7),arange(7,10)]
- compare_results(res,desired)
+ indices = [1, 5, 7]
+ res = array_split(a, indices, axis=-1)
+ desired = [arange(0, 1), arange(1, 5), arange(5, 7), arange(7, 10)]
+ compare_results(res, desired)
def test_index_split_low_bound(self):
a = arange(10)
- indices = [0,5,7]
- res = array_split(a,indices,axis=-1)
- desired = [array([]),arange(0,5),arange(5,7),arange(7,10)]
- compare_results(res,desired)
+ indices = [0, 5, 7]
+ res = array_split(a, indices, axis=-1)
+ desired = [array([]), arange(0, 5), arange(5, 7), arange(7, 10)]
+ compare_results(res, desired)
def test_index_split_high_bound(self):
a = arange(10)
- indices = [0,5,7,10,12]
- res = array_split(a,indices,axis=-1)
- desired = [array([]),arange(0,5),arange(5,7),arange(7,10),
- array([]),array([])]
- compare_results(res,desired)
+ indices = [0, 5, 7, 10, 12]
+ res = array_split(a, indices, axis=-1)
+ desired = [array([]), arange(0, 5), arange(5, 7), arange(7, 10),
+ array([]), array([])]
+ compare_results(res, desired)
class TestSplit(TestCase):
@@ -143,14 +143,14 @@ class TestSplit(TestCase):
*"""
def test_equal_split(self):
a = arange(10)
- res = split(a,2)
- desired = [arange(5),arange(5,10)]
- compare_results(res,desired)
+ res = split(a, 2)
+ desired = [arange(5), arange(5, 10)]
+ compare_results(res, desired)
def test_unequal_split(self):
a = arange(10)
try:
- res = split(a,3)
+ res = split(a, 3)
assert_(0) # should raise an error
except ValueError:
pass
@@ -159,27 +159,27 @@ class TestSplit(TestCase):
class TestDstack(TestCase):
def test_0D_array(self):
a = array(1); b = array(2);
- res=dstack([a,b])
- desired = array([[[1,2]]])
- assert_array_equal(res,desired)
+ res=dstack([a, b])
+ desired = array([[[1, 2]]])
+ assert_array_equal(res, desired)
def test_1D_array(self):
a = array([1]); b = array([2]);
- res=dstack([a,b])
- desired = array([[[1,2]]])
- assert_array_equal(res,desired)
+ res=dstack([a, b])
+ desired = array([[[1, 2]]])
+ assert_array_equal(res, desired)
def test_2D_array(self):
- a = array([[1],[2]]); b = array([[1],[2]]);
- res=dstack([a,b])
- desired = array([[[1,1]],[[2,2,]]])
- assert_array_equal(res,desired)
+ a = array([[1], [2]]); b = array([[1], [2]]);
+ res=dstack([a, b])
+ desired = array([[[1, 1]], [[2, 2,]]])
+ assert_array_equal(res, desired)
def test_2D_array2(self):
- a = array([1,2]); b = array([1,2]);
- res=dstack([a,b])
- desired = array([[[1,1],[2,2]]])
- assert_array_equal(res,desired)
+ a = array([1, 2]); b = array([1, 2]);
+ res=dstack([a, b])
+ desired = array([[[1, 1], [2, 2]]])
+ assert_array_equal(res, desired)
""" array_split has more comprehensive test of splitting.
only do simple test on hsplit, vsplit, and dsplit
@@ -190,75 +190,75 @@ class TestHsplit(TestCase):
def test_0D_array(self):
a= array(1)
try:
- hsplit(a,2)
+ hsplit(a, 2)
assert_(0)
except ValueError:
pass
def test_1D_array(self):
- a= array([1,2,3,4])
- res = hsplit(a,2)
- desired = [array([1,2]),array([3,4])]
- compare_results(res,desired)
+ a= array([1, 2, 3, 4])
+ res = hsplit(a, 2)
+ desired = [array([1, 2]), array([3, 4])]
+ compare_results(res, desired)
def test_2D_array(self):
- a= array([[1,2,3,4],
- [1,2,3,4]])
- res = hsplit(a,2)
- desired = [array([[1,2],[1,2]]),array([[3,4],[3,4]])]
- compare_results(res,desired)
+ a= array([[1, 2, 3, 4],
+ [1, 2, 3, 4]])
+ res = hsplit(a, 2)
+ desired = [array([[1, 2], [1, 2]]), array([[3, 4], [3, 4]])]
+ compare_results(res, desired)
class TestVsplit(TestCase):
""" only testing for integer splits.
"""
def test_1D_array(self):
- a= array([1,2,3,4])
+ a= array([1, 2, 3, 4])
try:
- vsplit(a,2)
+ vsplit(a, 2)
assert_(0)
except ValueError:
pass
def test_2D_array(self):
- a= array([[1,2,3,4],
- [1,2,3,4]])
- res = vsplit(a,2)
- desired = [array([[1,2,3,4]]),array([[1,2,3,4]])]
- compare_results(res,desired)
+ a= array([[1, 2, 3, 4],
+ [1, 2, 3, 4]])
+ res = vsplit(a, 2)
+ desired = [array([[1, 2, 3, 4]]), array([[1, 2, 3, 4]])]
+ compare_results(res, desired)
class TestDsplit(TestCase):
""" only testing for integer splits.
"""
def test_2D_array(self):
- a= array([[1,2,3,4],
- [1,2,3,4]])
+ a= array([[1, 2, 3, 4],
+ [1, 2, 3, 4]])
try:
- dsplit(a,2)
+ dsplit(a, 2)
assert_(0)
except ValueError:
pass
def test_3D_array(self):
- a= array([[[1,2,3,4],
- [1,2,3,4]],
- [[1,2,3,4],
- [1,2,3,4]]])
- res = dsplit(a,2)
- desired = [array([[[1,2],[1,2]],[[1,2],[1,2]]]),
- array([[[3,4],[3,4]],[[3,4],[3,4]]])]
- compare_results(res,desired)
+ a= array([[[1, 2, 3, 4],
+ [1, 2, 3, 4]],
+ [[1, 2, 3, 4],
+ [1, 2, 3, 4]]])
+ res = dsplit(a, 2)
+ desired = [array([[[1, 2], [1, 2]], [[1, 2], [1, 2]]]),
+ array([[[3, 4], [3, 4]], [[3, 4], [3, 4]]])]
+ compare_results(res, desired)
class TestSqueeze(TestCase):
def test_basic(self):
- a = rand(20,10,10,1,1)
- b = rand(20,1,10,1,20)
- c = rand(1,1,20,10)
- assert_array_equal(squeeze(a),reshape(a,(20,10,10)))
- assert_array_equal(squeeze(b),reshape(b,(20,10,20)))
- assert_array_equal(squeeze(c),reshape(c,(20,10)))
+ a = rand(20, 10, 10, 1, 1)
+ b = rand(20, 1, 10, 1, 20)
+ c = rand(1, 1, 20, 10)
+ assert_array_equal(squeeze(a), reshape(a, (20, 10, 10)))
+ assert_array_equal(squeeze(b), reshape(b, (20, 10, 20)))
+ assert_array_equal(squeeze(c), reshape(c, (20, 10)))
# Squeezing to 0-dim should still give an ndarray
a = [[[1.5]]]
@@ -270,44 +270,44 @@ class TestSqueeze(TestCase):
class TestKron(TestCase):
def test_return_type(self):
- a = ones([2,2])
+ a = ones([2, 2])
m = asmatrix(a)
- assert_equal(type(kron(a,a)), ndarray)
- assert_equal(type(kron(m,m)), matrix)
- assert_equal(type(kron(a,m)), matrix)
- assert_equal(type(kron(m,a)), matrix)
+ assert_equal(type(kron(a, a)), ndarray)
+ assert_equal(type(kron(m, m)), matrix)
+ assert_equal(type(kron(a, m)), matrix)
+ assert_equal(type(kron(m, a)), matrix)
class myarray(ndarray):
__array_priority__ = 0.0
ma = myarray(a.shape, a.dtype, a.data)
- assert_equal(type(kron(a,a)), ndarray)
- assert_equal(type(kron(ma,ma)), myarray)
- assert_equal(type(kron(a,ma)), ndarray)
- assert_equal(type(kron(ma,a)), myarray)
+ assert_equal(type(kron(a, a)), ndarray)
+ assert_equal(type(kron(ma, ma)), myarray)
+ assert_equal(type(kron(a, ma)), ndarray)
+ assert_equal(type(kron(ma, a)), myarray)
class TestTile(TestCase):
def test_basic(self):
- a = array([0,1,2])
- b = [[1,2],[3,4]]
- assert_equal(tile(a,2), [0,1,2,0,1,2])
- assert_equal(tile(a,(2,2)), [[0,1,2,0,1,2],[0,1,2,0,1,2]])
- assert_equal(tile(a,(1,2)), [[0,1,2,0,1,2]])
- assert_equal(tile(b, 2), [[1,2,1,2],[3,4,3,4]])
- assert_equal(tile(b,(2,1)),[[1,2],[3,4],[1,2],[3,4]])
- assert_equal(tile(b,(2,2)),[[1,2,1,2],[3,4,3,4],
- [1,2,1,2],[3,4,3,4]])
+ a = array([0, 1, 2])
+ b = [[1, 2], [3, 4]]
+ assert_equal(tile(a, 2), [0, 1, 2, 0, 1, 2])
+ assert_equal(tile(a, (2, 2)), [[0, 1, 2, 0, 1, 2], [0, 1, 2, 0, 1, 2]])
+ assert_equal(tile(a, (1, 2)), [[0, 1, 2, 0, 1, 2]])
+ assert_equal(tile(b, 2), [[1, 2, 1, 2], [3, 4, 3, 4]])
+ assert_equal(tile(b, (2, 1)), [[1, 2], [3, 4], [1, 2], [3, 4]])
+ assert_equal(tile(b, (2, 2)), [[1, 2, 1, 2], [3, 4, 3, 4],
+ [1, 2, 1, 2], [3, 4, 3, 4]])
def test_empty(self):
a = array([[[]]])
- d = tile(a,(3,2,5)).shape
- assert_equal(d,(3,2,0))
+ d = tile(a, (3, 2, 5)).shape
+ assert_equal(d, (3, 2, 0))
def test_kroncompare(self):
import numpy.random as nr
- reps=[(2,),(1,2),(2,1),(2,2),(2,3,2),(3,2)]
- shape=[(3,),(2,3),(3,4,3),(3,2,3),(4,3,2,4),(2,2)]
+ reps=[(2,), (1, 2), (2, 1), (2, 2), (2, 3, 2), (3, 2)]
+ shape=[(3,), (2, 3), (3, 4, 3), (3, 2, 3), (4, 3, 2, 4), (2, 2)]
for s in shape:
- b = nr.randint(0,10,size=s)
+ b = nr.randint(0, 10, size=s)
for r in reps:
a = ones(r, b.dtype)
large = tile(b, r)
@@ -331,9 +331,9 @@ class TestMayShareMemory(TestCase):
# Utility
-def compare_results(res,desired):
+def compare_results(res, desired):
for i in range(len(desired)):
- assert_array_equal(res[i],desired[i])
+ assert_array_equal(res[i], desired[i])
if __name__ == "__main__":
diff --git a/numpy/lib/tests/test_stride_tricks.py b/numpy/lib/tests/test_stride_tricks.py
index f815b247f..5d06e0a8c 100644
--- a/numpy/lib/tests/test_stride_tricks.py
+++ b/numpy/lib/tests/test_stride_tricks.py
@@ -52,10 +52,10 @@ def test_same():
assert_array_equal(y, by)
def test_one_off():
- x = np.array([[1,2,3]])
- y = np.array([[1],[2],[3]])
+ x = np.array([[1, 2, 3]])
+ y = np.array([[1], [2], [3]])
bx, by = broadcast_arrays(x, y)
- bx0 = np.array([[1,2,3],[1,2,3],[1,2,3]])
+ bx0 = np.array([[1, 2, 3], [1, 2, 3], [1, 2, 3]])
by0 = bx0.T
assert_array_equal(bx0, bx)
assert_array_equal(by0, by)
@@ -67,13 +67,13 @@ def test_same_input_shapes():
(),
(1,),
(3,),
- (0,1),
- (0,3),
- (1,0),
- (3,0),
- (1,3),
- (3,1),
- (3,3),
+ (0, 1),
+ (0, 3),
+ (1, 0),
+ (3, 0),
+ (1, 3),
+ (3, 1),
+ (3, 3),
]
for shape in data:
input_shapes = [shape]
@@ -92,18 +92,18 @@ def test_two_compatible_by_ones_input_shapes():
"""
data = [
[[(1,), (3,)], (3,)],
- [[(1,3), (3,3)], (3,3)],
- [[(3,1), (3,3)], (3,3)],
- [[(1,3), (3,1)], (3,3)],
- [[(1,1), (3,3)], (3,3)],
- [[(1,1), (1,3)], (1,3)],
- [[(1,1), (3,1)], (3,1)],
- [[(1,0), (0,0)], (0,0)],
- [[(0,1), (0,0)], (0,0)],
- [[(1,0), (0,1)], (0,0)],
- [[(1,1), (0,0)], (0,0)],
- [[(1,1), (1,0)], (1,0)],
- [[(1,1), (0,1)], (0,1)],
+ [[(1, 3), (3, 3)], (3, 3)],
+ [[(3, 1), (3, 3)], (3, 3)],
+ [[(1, 3), (3, 1)], (3, 3)],
+ [[(1, 1), (3, 3)], (3, 3)],
+ [[(1, 1), (1, 3)], (1, 3)],
+ [[(1, 1), (3, 1)], (3, 1)],
+ [[(1, 0), (0, 0)], (0, 0)],
+ [[(0, 1), (0, 0)], (0, 0)],
+ [[(1, 0), (0, 1)], (0, 0)],
+ [[(1, 1), (0, 0)], (0, 0)],
+ [[(1, 1), (1, 0)], (1, 0)],
+ [[(1, 1), (0, 1)], (0, 1)],
]
for input_shapes, expected_shape in data:
assert_shapes_correct(input_shapes, expected_shape)
@@ -116,25 +116,25 @@ def test_two_compatible_by_prepending_ones_input_shapes():
"""
data = [
[[(), (3,)], (3,)],
- [[(3,), (3,3)], (3,3)],
- [[(3,), (3,1)], (3,3)],
- [[(1,), (3,3)], (3,3)],
- [[(), (3,3)], (3,3)],
- [[(1,1), (3,)], (1,3)],
- [[(1,), (3,1)], (3,1)],
- [[(1,), (1,3)], (1,3)],
- [[(), (1,3)], (1,3)],
- [[(), (3,1)], (3,1)],
+ [[(3,), (3, 3)], (3, 3)],
+ [[(3,), (3, 1)], (3, 3)],
+ [[(1,), (3, 3)], (3, 3)],
+ [[(), (3, 3)], (3, 3)],
+ [[(1, 1), (3,)], (1, 3)],
+ [[(1,), (3, 1)], (3, 1)],
+ [[(1,), (1, 3)], (1, 3)],
+ [[(), (1, 3)], (1, 3)],
+ [[(), (3, 1)], (3, 1)],
[[(), (0,)], (0,)],
- [[(0,), (0,0)], (0,0)],
- [[(0,), (0,1)], (0,0)],
- [[(1,), (0,0)], (0,0)],
- [[(), (0,0)], (0,0)],
- [[(1,1), (0,)], (1,0)],
- [[(1,), (0,1)], (0,1)],
- [[(1,), (1,0)], (1,0)],
- [[(), (1,0)], (1,0)],
- [[(), (0,1)], (0,1)],
+ [[(0,), (0, 0)], (0, 0)],
+ [[(0,), (0, 1)], (0, 0)],
+ [[(1,), (0, 0)], (0, 0)],
+ [[(), (0, 0)], (0, 0)],
+ [[(1, 1), (0,)], (1, 0)],
+ [[(1,), (0, 1)], (0, 1)],
+ [[(1,), (1, 0)], (1, 0)],
+ [[(), (1, 0)], (1, 0)],
+ [[(), (0, 1)], (0, 1)],
]
for input_shapes, expected_shape in data:
assert_shapes_correct(input_shapes, expected_shape)
@@ -146,9 +146,9 @@ def test_incompatible_shapes_raise_valueerror():
"""
data = [
[(3,), (4,)],
- [(2,3), (2,)],
+ [(2, 3), (2,)],
[(3,), (3,), (4,)],
- [(1,3,4), (2,3,3)],
+ [(1, 3, 4), (2, 3, 3)],
]
for input_shapes in data:
assert_incompatible_shapes_raise(input_shapes)
@@ -160,38 +160,38 @@ def test_same_as_ufunc():
"""
data = [
[[(1,), (3,)], (3,)],
- [[(1,3), (3,3)], (3,3)],
- [[(3,1), (3,3)], (3,3)],
- [[(1,3), (3,1)], (3,3)],
- [[(1,1), (3,3)], (3,3)],
- [[(1,1), (1,3)], (1,3)],
- [[(1,1), (3,1)], (3,1)],
- [[(1,0), (0,0)], (0,0)],
- [[(0,1), (0,0)], (0,0)],
- [[(1,0), (0,1)], (0,0)],
- [[(1,1), (0,0)], (0,0)],
- [[(1,1), (1,0)], (1,0)],
- [[(1,1), (0,1)], (0,1)],
+ [[(1, 3), (3, 3)], (3, 3)],
+ [[(3, 1), (3, 3)], (3, 3)],
+ [[(1, 3), (3, 1)], (3, 3)],
+ [[(1, 1), (3, 3)], (3, 3)],
+ [[(1, 1), (1, 3)], (1, 3)],
+ [[(1, 1), (3, 1)], (3, 1)],
+ [[(1, 0), (0, 0)], (0, 0)],
+ [[(0, 1), (0, 0)], (0, 0)],
+ [[(1, 0), (0, 1)], (0, 0)],
+ [[(1, 1), (0, 0)], (0, 0)],
+ [[(1, 1), (1, 0)], (1, 0)],
+ [[(1, 1), (0, 1)], (0, 1)],
[[(), (3,)], (3,)],
- [[(3,), (3,3)], (3,3)],
- [[(3,), (3,1)], (3,3)],
- [[(1,), (3,3)], (3,3)],
- [[(), (3,3)], (3,3)],
- [[(1,1), (3,)], (1,3)],
- [[(1,), (3,1)], (3,1)],
- [[(1,), (1,3)], (1,3)],
- [[(), (1,3)], (1,3)],
- [[(), (3,1)], (3,1)],
+ [[(3,), (3, 3)], (3, 3)],
+ [[(3,), (3, 1)], (3, 3)],
+ [[(1,), (3, 3)], (3, 3)],
+ [[(), (3, 3)], (3, 3)],
+ [[(1, 1), (3,)], (1, 3)],
+ [[(1,), (3, 1)], (3, 1)],
+ [[(1,), (1, 3)], (1, 3)],
+ [[(), (1, 3)], (1, 3)],
+ [[(), (3, 1)], (3, 1)],
[[(), (0,)], (0,)],
- [[(0,), (0,0)], (0,0)],
- [[(0,), (0,1)], (0,0)],
- [[(1,), (0,0)], (0,0)],
- [[(), (0,0)], (0,0)],
- [[(1,1), (0,)], (1,0)],
- [[(1,), (0,1)], (0,1)],
- [[(1,), (1,0)], (1,0)],
- [[(), (1,0)], (1,0)],
- [[(), (0,1)], (0,1)],
+ [[(0,), (0, 0)], (0, 0)],
+ [[(0,), (0, 1)], (0, 0)],
+ [[(1,), (0, 0)], (0, 0)],
+ [[(), (0, 0)], (0, 0)],
+ [[(1, 1), (0,)], (1, 0)],
+ [[(1,), (0, 1)], (0, 1)],
+ [[(1,), (1, 0)], (1, 0)],
+ [[(), (1, 0)], (1, 0)],
+ [[(), (0, 1)], (0, 1)],
]
for input_shapes, expected_shape in data:
assert_same_as_ufunc(input_shapes[0], input_shapes[1],
diff --git a/numpy/lib/tests/test_twodim_base.py b/numpy/lib/tests/test_twodim_base.py
index 7e590c1db..4ec5c34a2 100644
--- a/numpy/lib/tests/test_twodim_base.py
+++ b/numpy/lib/tests/test_twodim_base.py
@@ -14,46 +14,46 @@ from numpy.compat import asbytes, asbytes_nested
def get_mat(n):
data = arange(n)
- data = add.outer(data,data)
+ data = add.outer(data, data)
return data
class TestEye(TestCase):
def test_basic(self):
- assert_equal(eye(4),array([[1,0,0,0],
- [0,1,0,0],
- [0,0,1,0],
- [0,0,0,1]]))
- assert_equal(eye(4,dtype='f'),array([[1,0,0,0],
- [0,1,0,0],
- [0,0,1,0],
- [0,0,0,1]],'f'))
- assert_equal(eye(3) == 1, eye(3,dtype=bool))
+ assert_equal(eye(4), array([[1, 0, 0, 0],
+ [0, 1, 0, 0],
+ [0, 0, 1, 0],
+ [0, 0, 0, 1]]))
+ assert_equal(eye(4, dtype='f'), array([[1, 0, 0, 0],
+ [0, 1, 0, 0],
+ [0, 0, 1, 0],
+ [0, 0, 0, 1]], 'f'))
+ assert_equal(eye(3) == 1, eye(3, dtype=bool))
def test_diag(self):
- assert_equal(eye(4,k=1),array([[0,1,0,0],
- [0,0,1,0],
- [0,0,0,1],
- [0,0,0,0]]))
- assert_equal(eye(4,k=-1),array([[0,0,0,0],
- [1,0,0,0],
- [0,1,0,0],
- [0,0,1,0]]))
+ assert_equal(eye(4, k=1), array([[0, 1, 0, 0],
+ [0, 0, 1, 0],
+ [0, 0, 0, 1],
+ [0, 0, 0, 0]]))
+ assert_equal(eye(4, k=-1), array([[0, 0, 0, 0],
+ [1, 0, 0, 0],
+ [0, 1, 0, 0],
+ [0, 0, 1, 0]]))
def test_2d(self):
- assert_equal(eye(4,3),array([[1,0,0],
- [0,1,0],
- [0,0,1],
- [0,0,0]]))
- assert_equal(eye(3,4),array([[1,0,0,0],
- [0,1,0,0],
- [0,0,1,0]]))
+ assert_equal(eye(4, 3), array([[1, 0, 0],
+ [0, 1, 0],
+ [0, 0, 1],
+ [0, 0, 0]]))
+ assert_equal(eye(3, 4), array([[1, 0, 0, 0],
+ [0, 1, 0, 0],
+ [0, 0, 1, 0]]))
def test_diag2d(self):
- assert_equal(eye(3,4,k=2),array([[0,0,1,0],
- [0,0,0,1],
- [0,0,0,0]]))
- assert_equal(eye(4,3,k=-2),array([[0,0,0],
- [0,0,0],
- [1,0,0],
- [0,1,0]]))
+ assert_equal(eye(3, 4, k=2), array([[0, 0, 1, 0],
+ [0, 0, 0, 1],
+ [0, 0, 0, 0]]))
+ assert_equal(eye(4, 3, k=-2), array([[0, 0, 0],
+ [0, 0, 0],
+ [1, 0, 0],
+ [0, 1, 0]]))
def test_eye_bounds(self):
assert_equal(eye(2, 2, 1), [[0, 1], [0, 0]])
@@ -93,7 +93,7 @@ class TestDiag(TestCase):
vals = (100 * get_mat(5) + 1).astype('l')
b = zeros((5,))
for k in range(5):
- b[k] = vals[k,k]
+ b[k] = vals[k, k]
assert_equal(diag(vals), b)
b = b * 0
for k in range(3):
@@ -123,61 +123,61 @@ class TestFliplr(TestCase):
def test_basic(self):
self.assertRaises(ValueError, fliplr, ones(4))
a = get_mat(4)
- b = a[:,::-1]
- assert_equal(fliplr(a),b)
- a = [[0,1,2],
- [3,4,5]]
- b = [[2,1,0],
- [5,4,3]]
- assert_equal(fliplr(a),b)
+ b = a[:, ::-1]
+ assert_equal(fliplr(a), b)
+ a = [[0, 1, 2],
+ [3, 4, 5]]
+ b = [[2, 1, 0],
+ [5, 4, 3]]
+ assert_equal(fliplr(a), b)
class TestFlipud(TestCase):
def test_basic(self):
a = get_mat(4)
b = a[::-1,:]
- assert_equal(flipud(a),b)
- a = [[0,1,2],
- [3,4,5]]
- b = [[3,4,5],
- [0,1,2]]
- assert_equal(flipud(a),b)
+ assert_equal(flipud(a), b)
+ a = [[0, 1, 2],
+ [3, 4, 5]]
+ b = [[3, 4, 5],
+ [0, 1, 2]]
+ assert_equal(flipud(a), b)
class TestRot90(TestCase):
def test_basic(self):
self.assertRaises(ValueError, rot90, ones(4))
- a = [[0,1,2],
- [3,4,5]]
- b1 = [[2,5],
- [1,4],
- [0,3]]
- b2 = [[5,4,3],
- [2,1,0]]
- b3 = [[3,0],
- [4,1],
- [5,2]]
- b4 = [[0,1,2],
- [3,4,5]]
-
- for k in range(-3,13,4):
- assert_equal(rot90(a,k=k),b1)
- for k in range(-2,13,4):
- assert_equal(rot90(a,k=k),b2)
- for k in range(-1,13,4):
- assert_equal(rot90(a,k=k),b3)
- for k in range(0,13,4):
- assert_equal(rot90(a,k=k),b4)
+ a = [[0, 1, 2],
+ [3, 4, 5]]
+ b1 = [[2, 5],
+ [1, 4],
+ [0, 3]]
+ b2 = [[5, 4, 3],
+ [2, 1, 0]]
+ b3 = [[3, 0],
+ [4, 1],
+ [5, 2]]
+ b4 = [[0, 1, 2],
+ [3, 4, 5]]
+
+ for k in range(-3, 13, 4):
+ assert_equal(rot90(a, k=k), b1)
+ for k in range(-2, 13, 4):
+ assert_equal(rot90(a, k=k), b2)
+ for k in range(-1, 13, 4):
+ assert_equal(rot90(a, k=k), b3)
+ for k in range(0, 13, 4):
+ assert_equal(rot90(a, k=k), b4)
def test_axes(self):
- a = ones((50,40,3))
- assert_equal(rot90(a).shape,(40,50,3))
+ a = ones((50, 40, 3))
+ assert_equal(rot90(a).shape, (40, 50, 3))
class TestHistogram2d(TestCase):
def test_simple(self):
x = array([ 0.41702200, 0.72032449, 0.00011437481, 0.302332573, 0.146755891])
y = array([ 0.09233859, 0.18626021, 0.34556073, 0.39676747, 0.53881673])
- xedges = np.linspace(0,1,10)
- yedges = np.linspace(0,1,10)
+ xedges = np.linspace(0, 1, 10)
+ yedges = np.linspace(0, 1, 10)
H = histogram2d(x, y, (xedges, yedges))[0]
answer = array([[0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 0, 0],
@@ -191,40 +191,40 @@ class TestHistogram2d(TestCase):
assert_array_equal(H.T, answer)
H = histogram2d(x, y, xedges)[0]
assert_array_equal(H.T, answer)
- H,xedges,yedges = histogram2d(list(range(10)),list(range(10)))
- assert_array_equal(H, eye(10,10))
- assert_array_equal(xedges, np.linspace(0,9,11))
- assert_array_equal(yedges, np.linspace(0,9,11))
+ H, xedges, yedges = histogram2d(list(range(10)), list(range(10)))
+ assert_array_equal(H, eye(10, 10))
+ assert_array_equal(xedges, np.linspace(0, 9, 11))
+ assert_array_equal(yedges, np.linspace(0, 9, 11))
def test_asym(self):
x = array([1, 1, 2, 3, 4, 4, 4, 5])
y = array([1, 3, 2, 0, 1, 2, 3, 4])
- H, xed, yed = histogram2d(x,y, (6, 5), range = [[0,6],[0,5]], normed=True)
- answer = array([[0.,0,0,0,0],
- [0,1,0,1,0],
- [0,0,1,0,0],
- [1,0,0,0,0],
- [0,1,1,1,0],
- [0,0,0,0,1]])
+ H, xed, yed = histogram2d(x, y, (6, 5), range = [[0, 6], [0, 5]], normed=True)
+ answer = array([[0., 0, 0, 0, 0],
+ [0, 1, 0, 1, 0],
+ [0, 0, 1, 0, 0],
+ [1, 0, 0, 0, 0],
+ [0, 1, 1, 1, 0],
+ [0, 0, 0, 0, 1]])
assert_array_almost_equal(H, answer/8., 3)
- assert_array_equal(xed, np.linspace(0,6,7))
- assert_array_equal(yed, np.linspace(0,5,6))
+ assert_array_equal(xed, np.linspace(0, 6, 7))
+ assert_array_equal(yed, np.linspace(0, 5, 6))
def test_norm(self):
- x = array([1,2,3,1,2,3,1,2,3])
- y = array([1,1,1,2,2,2,3,3,3])
- H, xed, yed = histogram2d(x,y,[[1,2,3,5], [1,2,3,5]], normed=True)
- answer=array([[1,1,.5],
- [1,1,.5],
- [.5,.5,.25]])/9.
+ x = array([1, 2, 3, 1, 2, 3, 1, 2, 3])
+ y = array([1, 1, 1, 2, 2, 2, 3, 3, 3])
+ H, xed, yed = histogram2d(x, y, [[1, 2, 3, 5], [1, 2, 3, 5]], normed=True)
+ answer=array([[1, 1, .5],
+ [1, 1, .5],
+ [.5, .5, .25]])/9.
assert_array_almost_equal(H, answer, 3)
def test_all_outliers(self):
r = rand(100)+1.
- H, xed, yed = histogram2d(r, r, (4, 5), range=([0,1], [0,1]))
+ H, xed, yed = histogram2d(r, r, (4, 5), range=([0, 1], [0, 1]))
assert_array_equal(H, 0)
def test_empty(self):
- a, edge1, edge2 = histogram2d([],[], bins=([0,1],[0,1]))
+ a, edge1, edge2 = histogram2d([], [], bins=([0, 1], [0, 1]))
assert_array_max_ulp(a, array([[ 0.]]))
a, edge1, edge2 = histogram2d([], [], bins=4)
@@ -233,11 +233,11 @@ class TestHistogram2d(TestCase):
class TestTri(TestCase):
def test_dtype(self):
- out = array([[1,0,0],
- [1,1,0],
- [1,1,1]])
- assert_array_equal(tri(3),out)
- assert_array_equal(tri(3,dtype=bool),out.astype(bool))
+ out = array([[1, 0, 0],
+ [1, 1, 0],
+ [1, 1, 1]])
+ assert_array_equal(tri(3), out)
+ assert_array_equal(tri(3, dtype=bool), out.astype(bool))
def test_tril_triu():
@@ -327,15 +327,15 @@ class TestTriuIndices(object):
class TestTrilIndicesFrom(object):
def test_exceptions(self):
assert_raises(ValueError, tril_indices_from, np.ones((2,)))
- assert_raises(ValueError, tril_indices_from, np.ones((2,2,2)))
- assert_raises(ValueError, tril_indices_from, np.ones((2,3)))
+ assert_raises(ValueError, tril_indices_from, np.ones((2, 2, 2)))
+ assert_raises(ValueError, tril_indices_from, np.ones((2, 3)))
class TestTriuIndicesFrom(object):
def test_exceptions(self):
assert_raises(ValueError, triu_indices_from, np.ones((2,)))
- assert_raises(ValueError, triu_indices_from, np.ones((2,2,2)))
- assert_raises(ValueError, triu_indices_from, np.ones((2,3)))
+ assert_raises(ValueError, triu_indices_from, np.ones((2, 2, 2)))
+ assert_raises(ValueError, triu_indices_from, np.ones((2, 3)))
if __name__ == "__main__":
diff --git a/numpy/lib/tests/test_type_check.py b/numpy/lib/tests/test_type_check.py
index 8b01a974a..3ca093e16 100644
--- a/numpy/lib/tests/test_type_check.py
+++ b/numpy/lib/tests/test_type_check.py
@@ -20,11 +20,11 @@ def assert_all(x):
class TestCommonType(TestCase):
def test_basic(self):
- ai32 = array([[1,2],[3,4]], dtype=int32)
- af32 = array([[1,2],[3,4]], dtype=float32)
- af64 = array([[1,2],[3,4]], dtype=float64)
- acs = array([[1+5j,2+6j],[3+7j,4+8j]], dtype=csingle)
- acd = array([[1+5j,2+6j],[3+7j,4+8j]], dtype=cdouble)
+ ai32 = array([[1, 2], [3, 4]], dtype=int32)
+ af32 = array([[1, 2], [3, 4]], dtype=float32)
+ af64 = array([[1, 2], [3, 4]], dtype=float64)
+ acs = array([[1+5j, 2+6j], [3+7j, 4+8j]], dtype=csingle)
+ acd = array([[1+5j, 2+6j], [3+7j, 4+8j]], dtype=cdouble)
assert_(common_type(af32) == float32)
assert_(common_type(af64) == float64)
assert_(common_type(acs) == csingle)
@@ -36,50 +36,50 @@ class TestMintypecode(TestCase):
def test_default_1(self):
for itype in '1bcsuwil':
- assert_equal(mintypecode(itype),'d')
- assert_equal(mintypecode('f'),'f')
- assert_equal(mintypecode('d'),'d')
- assert_equal(mintypecode('F'),'F')
- assert_equal(mintypecode('D'),'D')
+ assert_equal(mintypecode(itype), 'd')
+ assert_equal(mintypecode('f'), 'f')
+ assert_equal(mintypecode('d'), 'd')
+ assert_equal(mintypecode('F'), 'F')
+ assert_equal(mintypecode('D'), 'D')
def test_default_2(self):
for itype in '1bcsuwil':
- assert_equal(mintypecode(itype+'f'),'f')
- assert_equal(mintypecode(itype+'d'),'d')
- assert_equal(mintypecode(itype+'F'),'F')
- assert_equal(mintypecode(itype+'D'),'D')
- assert_equal(mintypecode('ff'),'f')
- assert_equal(mintypecode('fd'),'d')
- assert_equal(mintypecode('fF'),'F')
- assert_equal(mintypecode('fD'),'D')
- assert_equal(mintypecode('df'),'d')
- assert_equal(mintypecode('dd'),'d')
+ assert_equal(mintypecode(itype+'f'), 'f')
+ assert_equal(mintypecode(itype+'d'), 'd')
+ assert_equal(mintypecode(itype+'F'), 'F')
+ assert_equal(mintypecode(itype+'D'), 'D')
+ assert_equal(mintypecode('ff'), 'f')
+ assert_equal(mintypecode('fd'), 'd')
+ assert_equal(mintypecode('fF'), 'F')
+ assert_equal(mintypecode('fD'), 'D')
+ assert_equal(mintypecode('df'), 'd')
+ assert_equal(mintypecode('dd'), 'd')
#assert_equal(mintypecode('dF',savespace=1),'F')
- assert_equal(mintypecode('dF'),'D')
- assert_equal(mintypecode('dD'),'D')
- assert_equal(mintypecode('Ff'),'F')
+ assert_equal(mintypecode('dF'), 'D')
+ assert_equal(mintypecode('dD'), 'D')
+ assert_equal(mintypecode('Ff'), 'F')
#assert_equal(mintypecode('Fd',savespace=1),'F')
- assert_equal(mintypecode('Fd'),'D')
- assert_equal(mintypecode('FF'),'F')
- assert_equal(mintypecode('FD'),'D')
- assert_equal(mintypecode('Df'),'D')
- assert_equal(mintypecode('Dd'),'D')
- assert_equal(mintypecode('DF'),'D')
- assert_equal(mintypecode('DD'),'D')
+ assert_equal(mintypecode('Fd'), 'D')
+ assert_equal(mintypecode('FF'), 'F')
+ assert_equal(mintypecode('FD'), 'D')
+ assert_equal(mintypecode('Df'), 'D')
+ assert_equal(mintypecode('Dd'), 'D')
+ assert_equal(mintypecode('DF'), 'D')
+ assert_equal(mintypecode('DD'), 'D')
def test_default_3(self):
- assert_equal(mintypecode('fdF'),'D')
+ assert_equal(mintypecode('fdF'), 'D')
#assert_equal(mintypecode('fdF',savespace=1),'F')
- assert_equal(mintypecode('fdD'),'D')
- assert_equal(mintypecode('fFD'),'D')
- assert_equal(mintypecode('dFD'),'D')
-
- assert_equal(mintypecode('ifd'),'d')
- assert_equal(mintypecode('ifF'),'F')
- assert_equal(mintypecode('ifD'),'D')
- assert_equal(mintypecode('idF'),'D')
+ assert_equal(mintypecode('fdD'), 'D')
+ assert_equal(mintypecode('fFD'), 'D')
+ assert_equal(mintypecode('dFD'), 'D')
+
+ assert_equal(mintypecode('ifd'), 'd')
+ assert_equal(mintypecode('ifF'), 'F')
+ assert_equal(mintypecode('ifD'), 'D')
+ assert_equal(mintypecode('idF'), 'D')
#assert_equal(mintypecode('idF',savespace=1),'F')
- assert_equal(mintypecode('idD'),'D')
+ assert_equal(mintypecode('idD'), 'D')
class TestIsscalar(TestCase):
@@ -97,72 +97,72 @@ class TestReal(TestCase):
def test_real(self):
y = rand(10,)
- assert_array_equal(y,real(y))
+ assert_array_equal(y, real(y))
def test_cmplx(self):
y = rand(10,)+1j*rand(10,)
- assert_array_equal(y.real,real(y))
+ assert_array_equal(y.real, real(y))
class TestImag(TestCase):
def test_real(self):
y = rand(10,)
- assert_array_equal(0,imag(y))
+ assert_array_equal(0, imag(y))
def test_cmplx(self):
y = rand(10,)+1j*rand(10,)
- assert_array_equal(y.imag,imag(y))
+ assert_array_equal(y.imag, imag(y))
class TestIscomplex(TestCase):
def test_fail(self):
- z = array([-1,0,1])
+ z = array([-1, 0, 1])
res = iscomplex(z)
- assert_(not sometrue(res,axis=0))
+ assert_(not sometrue(res, axis=0))
def test_pass(self):
- z = array([-1j,1,0])
+ z = array([-1j, 1, 0])
res = iscomplex(z)
- assert_array_equal(res,[1,0,0])
+ assert_array_equal(res, [1, 0, 0])
class TestIsreal(TestCase):
def test_pass(self):
- z = array([-1,0,1j])
+ z = array([-1, 0, 1j])
res = isreal(z)
- assert_array_equal(res,[1,1,0])
+ assert_array_equal(res, [1, 1, 0])
def test_fail(self):
- z = array([-1j,1,0])
+ z = array([-1j, 1, 0])
res = isreal(z)
- assert_array_equal(res,[0,1,1])
+ assert_array_equal(res, [0, 1, 1])
class TestIscomplexobj(TestCase):
def test_basic(self):
- z = array([-1,0,1])
+ z = array([-1, 0, 1])
assert_(not iscomplexobj(z))
- z = array([-1j,0,-1])
+ z = array([-1j, 0, -1])
assert_(iscomplexobj(z))
class TestIsrealobj(TestCase):
def test_basic(self):
- z = array([-1,0,1])
+ z = array([-1, 0, 1])
assert_(isrealobj(z))
- z = array([-1j,0,-1])
+ z = array([-1j, 0, -1])
assert_(not isrealobj(z))
class TestIsnan(TestCase):
def test_goodvalues(self):
- z = array((-1.,0.,1.))
+ z = array((-1., 0., 1.))
res = isnan(z) == 0
- assert_all(alltrue(res,axis=0))
+ assert_all(alltrue(res, axis=0))
def test_posinf(self):
with errstate(divide='ignore'):
@@ -193,9 +193,9 @@ class TestIsnan(TestCase):
class TestIsfinite(TestCase):
def test_goodvalues(self):
- z = array((-1.,0.,1.))
+ z = array((-1., 0., 1.))
res = isfinite(z) == 1
- assert_all(alltrue(res,axis=0))
+ assert_all(alltrue(res, axis=0))
def test_posinf(self):
with errstate(divide='ignore', invalid='ignore'):
@@ -226,9 +226,9 @@ class TestIsfinite(TestCase):
class TestIsinf(TestCase):
def test_goodvalues(self):
- z = array((-1.,0.,1.))
+ z = array((-1., 0., 1.))
res = isinf(z) == 0
- assert_all(alltrue(res,axis=0))
+ assert_all(alltrue(res, axis=0))
def test_posinf(self):
with errstate(divide='ignore', invalid='ignore'):
@@ -259,7 +259,7 @@ class TestIsposinf(TestCase):
def test_generic(self):
with errstate(divide='ignore', invalid='ignore'):
- vals = isposinf(array((-1.,0,1))/0.)
+ vals = isposinf(array((-1., 0, 1))/0.)
assert_(vals[0] == 0)
assert_(vals[1] == 0)
assert_(vals[2] == 1)
@@ -269,7 +269,7 @@ class TestIsneginf(TestCase):
def test_generic(self):
with errstate(divide='ignore', invalid='ignore'):
- vals = isneginf(array((-1.,0,1))/0.)
+ vals = isneginf(array((-1., 0, 1))/0.)
assert_(vals[0] == 1)
assert_(vals[1] == 0)
assert_(vals[2] == 0)
@@ -279,7 +279,7 @@ class TestNanToNum(TestCase):
def test_generic(self):
with errstate(divide='ignore', invalid='ignore'):
- vals = nan_to_num(array((-1.,0,1))/0.)
+ vals = nan_to_num(array((-1., 0, 1))/0.)
assert_all(vals[0] < -1e10) and assert_all(isfinite(vals[0]))
assert_(vals[1] == 0)
assert_all(vals[2] > 1e10) and assert_all(isfinite(vals[2]))
@@ -319,19 +319,19 @@ class TestRealIfClose(TestCase):
a = rand(10)
b = real_if_close(a+1e-15j)
assert_all(isrealobj(b))
- assert_array_equal(a,b)
+ assert_array_equal(a, b)
b = real_if_close(a+1e-7j)
assert_all(iscomplexobj(b))
- b = real_if_close(a+1e-7j,tol=1e-6)
+ b = real_if_close(a+1e-7j, tol=1e-6)
assert_all(isrealobj(b))
class TestArrayConversion(TestCase):
def test_asfarray(self):
- a = asfarray(array([1,2,3]))
- assert_equal(a.__class__,ndarray)
- assert_(issubdtype(a.dtype,float))
+ a = asfarray(array([1, 2, 3]))
+ assert_equal(a.__class__, ndarray)
+ assert_(issubdtype(a.dtype, float))
if __name__ == "__main__":
run_module_suite()
diff --git a/numpy/lib/tests/test_ufunclike.py b/numpy/lib/tests/test_ufunclike.py
index 50f3229e8..31dbdba1a 100644
--- a/numpy/lib/tests/test_ufunclike.py
+++ b/numpy/lib/tests/test_ufunclike.py
@@ -54,7 +54,7 @@ class TestUfunclike(TestCase):
a = nx.array([1.1, -1.1])
m = MyArray(a, metadata='foo')
f = ufl.fix(m)
- assert_array_equal(f, nx.array([1,-1]))
+ assert_array_equal(f, nx.array([1, -1]))
assert_(isinstance(f, MyArray))
assert_equal(f.metadata, 'foo')