summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_twodim_base.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/lib/tests/test_twodim_base.py')
-rw-r--r--numpy/lib/tests/test_twodim_base.py202
1 files changed, 101 insertions, 101 deletions
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__":