comparison DEPENDENCIES/mingw32/Python27/Lib/site-packages/numpy/tests/test_matlib.py @ 87:2a2c65a20a8b

Add Python libs and headers
author Chris Cannam
date Wed, 25 Feb 2015 14:05:22 +0000
parents
children
comparison
equal deleted inserted replaced
86:413a9d26189e 87:2a2c65a20a8b
1 from __future__ import division, absolute_import, print_function
2
3 import numpy as np
4 import numpy.matlib
5 from numpy.testing import assert_array_equal, assert_, run_module_suite
6
7 def test_empty():
8 x = np.matlib.empty((2,))
9 assert_(isinstance(x, np.matrix))
10 assert_(x.shape, (1, 2))
11
12 def test_ones():
13 assert_array_equal(np.matlib.ones((2, 3)),
14 np.matrix([[ 1., 1., 1.],
15 [ 1., 1., 1.]]))
16
17 assert_array_equal(np.matlib.ones(2), np.matrix([[ 1., 1.]]))
18
19 def test_zeros():
20 assert_array_equal(np.matlib.zeros((2, 3)),
21 np.matrix([[ 0., 0., 0.],
22 [ 0., 0., 0.]]))
23
24 assert_array_equal(np.matlib.zeros(2), np.matrix([[ 0., 0.]]))
25
26 def test_identity():
27 x = np.matlib.identity(2, dtype=np.int)
28 assert_array_equal(x, np.matrix([[1, 0], [0, 1]]))
29
30 def test_eye():
31 x = np.matlib.eye(3, k=1, dtype=int)
32 assert_array_equal(x, np.matrix([[ 0, 1, 0],
33 [ 0, 0, 1],
34 [ 0, 0, 0]]))
35
36 def test_rand():
37 x = np.matlib.rand(3)
38 # check matrix type, array would have shape (3,)
39 assert_(x.ndim == 2)
40
41 def test_randn():
42 x = np.matlib.randn(3)
43 # check matrix type, array would have shape (3,)
44 assert_(x.ndim == 2)
45
46 def test_repmat():
47 a1 = np.arange(4)
48 x = np.matlib.repmat(a1, 2, 2)
49 y = np.array([[0, 1, 2, 3, 0, 1, 2, 3],
50 [0, 1, 2, 3, 0, 1, 2, 3]])
51 assert_array_equal(x, y)
52
53
54 if __name__ == "__main__":
55 run_module_suite()