diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/tests/test_scalarmath.py | 22 | ||||
-rw-r--r-- | numpy/core/tests/test_ufunc.py | 11 | ||||
-rwxr-xr-x | numpy/doc/swig/test/testFarray.py | 8 | ||||
-rwxr-xr-x | numpy/doc/swig/test/testMatrix.py | 30 | ||||
-rwxr-xr-x | numpy/doc/swig/test/testTensor.py | 30 | ||||
-rwxr-xr-x | numpy/doc/swig/test/testVector.py | 30 | ||||
-rw-r--r-- | numpy/lib/getlimits.py | 4 | ||||
-rw-r--r-- | numpy/lib/tests/test_getlimits.py | 10 | ||||
-rw-r--r-- | numpy/lib/tests/test_polynomial.py | 8 | ||||
-rw-r--r-- | numpy/matlib.py | 15 | ||||
-rw-r--r-- | numpy/oldnumeric/functions.py | 42 | ||||
-rw-r--r-- | numpy/oldnumeric/typeconv.py | 38 | ||||
-rw-r--r-- | numpy/random/tests/test_random.py | 6 | ||||
-rw-r--r-- | numpy/tests/test_ctypeslib.py | 54 |
14 files changed, 149 insertions, 159 deletions
diff --git a/numpy/core/tests/test_scalarmath.py b/numpy/core/tests/test_scalarmath.py index 080c51fd4..e5c8aeeae 100644 --- a/numpy/core/tests/test_scalarmath.py +++ b/numpy/core/tests/test_scalarmath.py @@ -1,14 +1,12 @@ from numpy.testing import * -set_package_path() import numpy.core.umath as ncu from numpy import array -import numpy as N -restore_path() +import numpy as np -types = [N.bool_, N.byte, N.ubyte, N.short, N.ushort, N.intc, N.uintc, - N.int_, N.uint, N.longlong, N.ulonglong, - N.single, N.double, N.longdouble, N.csingle, - N.cdouble, N.clongdouble] +types = [np.bool_, np.byte, np.ubyte, np.short, np.ushort, np.intc, np.uintc, + np.int_, np.uint, np.longlong, np.ulonglong, + np.single, np.double, np.longdouble, np.csingle, + np.cdouble, np.clongdouble] # This compares scalarmath against ufuncs. @@ -40,13 +38,13 @@ class TestTypes(NumpyTestCase): class TestPower(NumpyTestCase): def check_small_types(self): - for t in [N.int8, N.int16]: + for t in [np.int8, np.int16]: a = t(3) b = a ** 4 assert b == 81, "error with %r: got %r" % (t,b) def check_large_types(self): - for t in [N.int32, N.int64, N.float32, N.float64, N.longdouble]: + for t in [np.int32, np.int64, np.float32, np.float64, np.longdouble]: a = t(51) b = a ** 4 assert b == 6765201, "error with %r: got %r" % (t,b) @@ -55,11 +53,11 @@ class TestConversion(NumpyTestCase): def test_int_from_long(self): l = [1e6, 1e12, 1e18, -1e6, -1e12, -1e18] li = [10**6, 10**12, 10**18, -10**6, -10**12, -10**18] - for T in [None,N.float64,N.int64]: - a = N.array(l,dtype=T) + for T in [None, np.float64, np.int64]: + a = np.array(l,dtype=T) assert_equal(map(int,a), li) - a = N.array(l[:3],dtype=N.uint64) + a = np.array(l[:3], dtype=np.uint64) assert_equal(map(int,a), li[:3]) #class TestRepr(NumpyTestCase): diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py index d07713b68..f9e923538 100644 --- a/numpy/core/tests/test_ufunc.py +++ b/numpy/core/tests/test_ufunc.py @@ -1,15 +1,12 @@ +import numpy as np from numpy.testing import * -set_package_path() -import numpy as N -restore_path() - class TestUfunc(NumpyTestCase): def test_reduceat_shifting_sum(self): L = 6 - x = N.arange(L) - idx = N.array(zip(N.arange(L-2),N.arange(L-2)+2)).ravel() - assert_array_equal(N.add.reduceat(x,idx)[::2], + x = np.arange(L) + idx = np.array(zip(np.arange(L-2), np.arange(L-2)+2)).ravel() + assert_array_equal(np.add.reduceat(x,idx)[::2], [1,3,5,7]) if __name__ == "__main__": diff --git a/numpy/doc/swig/test/testFarray.py b/numpy/doc/swig/test/testFarray.py index 47c39136a..614e149bd 100755 --- a/numpy/doc/swig/test/testFarray.py +++ b/numpy/doc/swig/test/testFarray.py @@ -7,8 +7,8 @@ import sys import unittest # Import NumPy -import numpy as N -major, minor = [ int(d) for d in N.__version__.split(".")[:2] ] +import numpy as np +major, minor = [ int(d) for d in np.__version__.split(".")[:2] ] if major == 0: BadListError = TypeError else: BadListError = ValueError @@ -136,7 +136,7 @@ class FarrayTestCase(unittest.TestCase): for j in range(self.ncols): self.array[i,j] = i+j a = self.array.view() - self.failUnless(isinstance(a, N.ndarray)) + self.failUnless(isinstance(a, np.ndarray)) self.failUnless(a.flags.f_contiguous) for i in range(self.nrows): for j in range(self.ncols): @@ -152,7 +152,7 @@ if __name__ == "__main__": # Execute the test suite print "Testing Classes of Module Farray" - print "NumPy version", N.__version__ + print "NumPy version", np.__version__ print result = unittest.TextTestRunner(verbosity=2).run(suite) sys.exit(len(result.errors) + len(result.failures)) diff --git a/numpy/doc/swig/test/testMatrix.py b/numpy/doc/swig/test/testMatrix.py index 933423fe9..f78dd2be2 100755 --- a/numpy/doc/swig/test/testMatrix.py +++ b/numpy/doc/swig/test/testMatrix.py @@ -7,8 +7,8 @@ import sys import unittest # Import NumPy -import numpy as N -major, minor = [ int(d) for d in N.__version__.split(".")[:2] ] +import numpy as np +major, minor = [ int(d) for d in np.__version__.split(".")[:2] ] if major == 0: BadListError = TypeError else: BadListError = ValueError @@ -131,7 +131,7 @@ class MatrixTestCase(unittest.TestCase): "Test scale function" print >>sys.stderr, self.typeStr, "... ", scale = Matrix.__dict__[self.typeStr + "Scale"] - matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],self.typeCode) + matrix = np.array([[1,2,3],[2,1,2],[3,2,1]],self.typeCode) scale(matrix,4) self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True) @@ -140,7 +140,7 @@ class MatrixTestCase(unittest.TestCase): "Test scale function with wrong dimensions" print >>sys.stderr, self.typeStr, "... ", scale = Matrix.__dict__[self.typeStr + "Scale"] - matrix = N.array([1,2,2,1],self.typeCode) + matrix = np.array([1,2,2,1],self.typeCode) self.assertRaises(TypeError, scale, matrix) # Test (type INPLACE_ARRAY2[ANY][ANY]) typemap @@ -148,7 +148,7 @@ class MatrixTestCase(unittest.TestCase): "Test scale function with wrong size" print >>sys.stderr, self.typeStr, "... ", scale = Matrix.__dict__[self.typeStr + "Scale"] - matrix = N.array([[1,2],[2,1]],self.typeCode) + matrix = np.array([[1,2],[2,1]],self.typeCode) self.assertRaises(TypeError, scale, matrix) # Test (type INPLACE_ARRAY2[ANY][ANY]) typemap @@ -156,7 +156,7 @@ class MatrixTestCase(unittest.TestCase): "Test scale function with wrong type" print >>sys.stderr, self.typeStr, "... ", scale = Matrix.__dict__[self.typeStr + "Scale"] - matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'c') + matrix = np.array([[1,2,3],[2,1,2],[3,2,1]],'c') self.assertRaises(TypeError, scale, matrix) # Test (type INPLACE_ARRAY2[ANY][ANY]) typemap @@ -172,16 +172,16 @@ class MatrixTestCase(unittest.TestCase): "Test floor function" print >>sys.stderr, self.typeStr, "... ", floor = Matrix.__dict__[self.typeStr + "Floor"] - matrix = N.array([[6,7],[8,9]],self.typeCode) + matrix = np.array([[6,7],[8,9]],self.typeCode) floor(matrix,7) - N.testing.assert_array_equal(matrix, N.array([[7,7],[8,9]])) + np.testing.assert_array_equal(matrix, np.array([[7,7],[8,9]])) # Test (type* INPLACE_ARRAY2, int DIM1, int DIM2) typemap def testFloorWrongDim(self): "Test floor function with wrong dimensions" print >>sys.stderr, self.typeStr, "... ", floor = Matrix.__dict__[self.typeStr + "Floor"] - matrix = N.array([6,7,8,9],self.typeCode) + matrix = np.array([6,7,8,9],self.typeCode) self.assertRaises(TypeError, floor, matrix) # Test (type* INPLACE_ARRAY2, int DIM1, int DIM2) typemap @@ -189,7 +189,7 @@ class MatrixTestCase(unittest.TestCase): "Test floor function with wrong type" print >>sys.stderr, self.typeStr, "... ", floor = Matrix.__dict__[self.typeStr + "Floor"] - matrix = N.array([[6,7], [8,9]],'c') + matrix = np.array([[6,7], [8,9]],'c') self.assertRaises(TypeError, floor, matrix) # Test (type* INPLACE_ARRAY2, int DIM1, int DIM2) typemap @@ -205,16 +205,16 @@ class MatrixTestCase(unittest.TestCase): "Test ceil function" print >>sys.stderr, self.typeStr, "... ", ceil = Matrix.__dict__[self.typeStr + "Ceil"] - matrix = N.array([[1,2],[3,4]],self.typeCode) + matrix = np.array([[1,2],[3,4]],self.typeCode) ceil(matrix,3) - N.testing.assert_array_equal(matrix, N.array([[1,2],[3,3]])) + np.testing.assert_array_equal(matrix, np.array([[1,2],[3,3]])) # Test (int DIM1, int DIM2, type* INPLACE_ARRAY2) typemap def testCeilWrongDim(self): "Test ceil function with wrong dimensions" print >>sys.stderr, self.typeStr, "... ", ceil = Matrix.__dict__[self.typeStr + "Ceil"] - matrix = N.array([1,2,3,4],self.typeCode) + matrix = np.array([1,2,3,4],self.typeCode) self.assertRaises(TypeError, ceil, matrix) # Test (int DIM1, int DIM2, type* INPLACE_ARRAY2) typemap @@ -222,7 +222,7 @@ class MatrixTestCase(unittest.TestCase): "Test ceil function with wrong dimensions" print >>sys.stderr, self.typeStr, "... ", ceil = Matrix.__dict__[self.typeStr + "Ceil"] - matrix = N.array([[1,2], [3,4]],'c') + matrix = np.array([[1,2], [3,4]],'c') self.assertRaises(TypeError, ceil, matrix) # Test (int DIM1, int DIM2, type* INPLACE_ARRAY2) typemap @@ -359,7 +359,7 @@ if __name__ == "__main__": # Execute the test suite print "Testing 2D Functions of Module Matrix" - print "NumPy version", N.__version__ + print "NumPy version", np.__version__ print result = unittest.TextTestRunner(verbosity=2).run(suite) sys.exit(len(result.errors) + len(result.failures)) diff --git a/numpy/doc/swig/test/testTensor.py b/numpy/doc/swig/test/testTensor.py index f68e6b720..7d13a0757 100755 --- a/numpy/doc/swig/test/testTensor.py +++ b/numpy/doc/swig/test/testTensor.py @@ -8,8 +8,8 @@ import sys import unittest # Import NumPy -import numpy as N -major, minor = [ int(d) for d in N.__version__.split(".")[:2] ] +import numpy as np +major, minor = [ int(d) for d in np.__version__.split(".")[:2] ] if major == 0: BadListError = TypeError else: BadListError = ValueError @@ -144,7 +144,7 @@ class TensorTestCase(unittest.TestCase): "Test scale function" print >>sys.stderr, self.typeStr, "... ", scale = Tensor.__dict__[self.typeStr + "Scale"] - tensor = N.array([[[1,0,1], [0,1,0], [1,0,1]], + tensor = np.array([[[1,0,1], [0,1,0], [1,0,1]], [[0,1,0], [1,0,1], [0,1,0]], [[1,0,1], [0,1,0], [1,0,1]]],self.typeCode) scale(tensor,4) @@ -157,7 +157,7 @@ class TensorTestCase(unittest.TestCase): "Test scale function with wrong type" print >>sys.stderr, self.typeStr, "... ", scale = Tensor.__dict__[self.typeStr + "Scale"] - tensor = N.array([[[1,0,1], [0,1,0], [1,0,1]], + tensor = np.array([[[1,0,1], [0,1,0], [1,0,1]], [[0,1,0], [1,0,1], [0,1,0]], [[1,0,1], [0,1,0], [1,0,1]]],'c') self.assertRaises(TypeError, scale, tensor) @@ -167,7 +167,7 @@ class TensorTestCase(unittest.TestCase): "Test scale function with wrong dimensions" print >>sys.stderr, self.typeStr, "... ", scale = Tensor.__dict__[self.typeStr + "Scale"] - tensor = N.array([[1,0,1], [0,1,0], [1,0,1], + tensor = np.array([[1,0,1], [0,1,0], [1,0,1], [0,1,0], [1,0,1], [0,1,0]],self.typeCode) self.assertRaises(TypeError, scale, tensor) @@ -176,7 +176,7 @@ class TensorTestCase(unittest.TestCase): "Test scale function with wrong size" print >>sys.stderr, self.typeStr, "... ", scale = Tensor.__dict__[self.typeStr + "Scale"] - tensor = N.array([[[1,0], [0,1], [1,0]], + tensor = np.array([[[1,0], [0,1], [1,0]], [[0,1], [1,0], [0,1]], [[1,0], [0,1], [1,0]]],self.typeCode) self.assertRaises(TypeError, scale, tensor) @@ -193,10 +193,10 @@ class TensorTestCase(unittest.TestCase): "Test floor function" print >>sys.stderr, self.typeStr, "... ", floor = Tensor.__dict__[self.typeStr + "Floor"] - tensor = N.array([[[1,2], [3,4]], + tensor = np.array([[[1,2], [3,4]], [[5,6], [7,8]]],self.typeCode) floor(tensor,4) - N.testing.assert_array_equal(tensor, N.array([[[4,4], [4,4]], + np.testing.assert_array_equal(tensor, np.array([[[4,4], [4,4]], [[5,6], [7,8]]])) # Test (type* INPLACE_ARRAY3, int DIM1, int DIM2, int DIM3) typemap @@ -204,7 +204,7 @@ class TensorTestCase(unittest.TestCase): "Test floor function with wrong type" print >>sys.stderr, self.typeStr, "... ", floor = Tensor.__dict__[self.typeStr + "Floor"] - tensor = N.array([[[1,2], [3,4]], + tensor = np.array([[[1,2], [3,4]], [[5,6], [7,8]]],'c') self.assertRaises(TypeError, floor, tensor) @@ -213,7 +213,7 @@ class TensorTestCase(unittest.TestCase): "Test floor function with wrong type" print >>sys.stderr, self.typeStr, "... ", floor = Tensor.__dict__[self.typeStr + "Floor"] - tensor = N.array([[1,2], [3,4], [5,6], [7,8]],self.typeCode) + tensor = np.array([[1,2], [3,4], [5,6], [7,8]],self.typeCode) self.assertRaises(TypeError, floor, tensor) # Test (type* INPLACE_ARRAY3, int DIM1, int DIM2, int DIM3) typemap @@ -228,10 +228,10 @@ class TensorTestCase(unittest.TestCase): "Test ceil function" print >>sys.stderr, self.typeStr, "... ", ceil = Tensor.__dict__[self.typeStr + "Ceil"] - tensor = N.array([[[9,8], [7,6]], + tensor = np.array([[[9,8], [7,6]], [[5,4], [3,2]]],self.typeCode) ceil(tensor,5) - N.testing.assert_array_equal(tensor, N.array([[[5,5], [5,5]], + np.testing.assert_array_equal(tensor, np.array([[[5,5], [5,5]], [[5,4], [3,2]]])) # Test (int DIM1, int DIM2, int DIM3, type* INPLACE_ARRAY3) typemap @@ -239,7 +239,7 @@ class TensorTestCase(unittest.TestCase): "Test ceil function with wrong type" print >>sys.stderr, self.typeStr, "... ", ceil = Tensor.__dict__[self.typeStr + "Ceil"] - tensor = N.array([[[9,8], [7,6]], + tensor = np.array([[[9,8], [7,6]], [[5,4], [3,2]]],'c') self.assertRaises(TypeError, ceil, tensor) @@ -248,7 +248,7 @@ class TensorTestCase(unittest.TestCase): "Test ceil function with wrong dimensions" print >>sys.stderr, self.typeStr, "... ", ceil = Tensor.__dict__[self.typeStr + "Ceil"] - tensor = N.array([[9,8], [7,6], [5,4], [3,2]], self.typeCode) + tensor = np.array([[9,8], [7,6], [5,4], [3,2]], self.typeCode) self.assertRaises(TypeError, ceil, tensor) # Test (int DIM1, int DIM2, int DIM3, type* INPLACE_ARRAY3) typemap @@ -399,7 +399,7 @@ if __name__ == "__main__": # Execute the test suite print "Testing 3D Functions of Module Tensor" - print "NumPy version", N.__version__ + print "NumPy version", np.__version__ print result = unittest.TextTestRunner(verbosity=2).run(suite) sys.exit(len(result.errors) + len(result.failures)) diff --git a/numpy/doc/swig/test/testVector.py b/numpy/doc/swig/test/testVector.py index 82a922e25..ed085aa94 100755 --- a/numpy/doc/swig/test/testVector.py +++ b/numpy/doc/swig/test/testVector.py @@ -7,8 +7,8 @@ import sys import unittest # Import NumPy -import numpy as N -major, minor = [ int(d) for d in N.__version__.split(".")[:2] ] +import numpy as np +major, minor = [ int(d) for d in np.__version__.split(".")[:2] ] if major == 0: BadListError = TypeError else: BadListError = ValueError @@ -123,7 +123,7 @@ class VectorTestCase(unittest.TestCase): "Test reverse function" print >>sys.stderr, self.typeStr, "... ", reverse = Vector.__dict__[self.typeStr + "Reverse"] - vector = N.array([1,2,4],self.typeCode) + vector = np.array([1,2,4],self.typeCode) reverse(vector) self.assertEquals((vector == [4,2,1]).all(), True) @@ -132,7 +132,7 @@ class VectorTestCase(unittest.TestCase): "Test reverse function with wrong dimensions" print >>sys.stderr, self.typeStr, "... ", reverse = Vector.__dict__[self.typeStr + "Reverse"] - vector = N.array([[1,2], [3,4]],self.typeCode) + vector = np.array([[1,2], [3,4]],self.typeCode) self.assertRaises(TypeError, reverse, vector) # Test the (type INPLACE_ARRAY1[ANY]) typemap @@ -140,7 +140,7 @@ class VectorTestCase(unittest.TestCase): "Test reverse function with wrong size" print >>sys.stderr, self.typeStr, "... ", reverse = Vector.__dict__[self.typeStr + "Reverse"] - vector = N.array([9,8,7,6,5,4],self.typeCode) + vector = np.array([9,8,7,6,5,4],self.typeCode) self.assertRaises(TypeError, reverse, vector) # Test the (type INPLACE_ARRAY1[ANY]) typemap @@ -148,7 +148,7 @@ class VectorTestCase(unittest.TestCase): "Test reverse function with wrong type" print >>sys.stderr, self.typeStr, "... ", reverse = Vector.__dict__[self.typeStr + "Reverse"] - vector = N.array([1,2,4],'c') + vector = np.array([1,2,4],'c') self.assertRaises(TypeError, reverse, vector) # Test the (type INPLACE_ARRAY1[ANY]) typemap @@ -163,16 +163,16 @@ class VectorTestCase(unittest.TestCase): "Test ones function" print >>sys.stderr, self.typeStr, "... ", ones = Vector.__dict__[self.typeStr + "Ones"] - vector = N.zeros(5,self.typeCode) + vector = np.zeros(5,self.typeCode) ones(vector) - N.testing.assert_array_equal(vector, N.array([1,1,1,1,1])) + np.testing.assert_array_equal(vector, np.array([1,1,1,1,1])) # Test the (type* INPLACE_ARRAY1, int DIM1) typemap def testOnesWrongDim(self): "Test ones function with wrong dimensions" print >>sys.stderr, self.typeStr, "... ", ones = Vector.__dict__[self.typeStr + "Ones"] - vector = N.zeros((5,5),self.typeCode) + vector = np.zeros((5,5),self.typeCode) self.assertRaises(TypeError, ones, vector) # Test the (type* INPLACE_ARRAY1, int DIM1) typemap @@ -180,7 +180,7 @@ class VectorTestCase(unittest.TestCase): "Test ones function with wrong type" print >>sys.stderr, self.typeStr, "... ", ones = Vector.__dict__[self.typeStr + "Ones"] - vector = N.zeros((5,5),'c') + vector = np.zeros((5,5),'c') self.assertRaises(TypeError, ones, vector) # Test the (type* INPLACE_ARRAY1, int DIM1) typemap @@ -195,16 +195,16 @@ class VectorTestCase(unittest.TestCase): "Test zeros function" print >>sys.stderr, self.typeStr, "... ", zeros = Vector.__dict__[self.typeStr + "Zeros"] - vector = N.ones(5,self.typeCode) + vector = np.ones(5,self.typeCode) zeros(vector) - N.testing.assert_array_equal(vector, N.array([0,0,0,0,0])) + np.testing.assert_array_equal(vector, np.array([0,0,0,0,0])) # Test the (int DIM1, type* INPLACE_ARRAY1) typemap def testZerosWrongDim(self): "Test zeros function with wrong dimensions" print >>sys.stderr, self.typeStr, "... ", zeros = Vector.__dict__[self.typeStr + "Zeros"] - vector = N.ones((5,5),self.typeCode) + vector = np.ones((5,5),self.typeCode) self.assertRaises(TypeError, zeros, vector) # Test the (int DIM1, type* INPLACE_ARRAY1) typemap @@ -212,7 +212,7 @@ class VectorTestCase(unittest.TestCase): "Test zeros function with wrong type" print >>sys.stderr, self.typeStr, "... ", zeros = Vector.__dict__[self.typeStr + "Zeros"] - vector = N.ones(6,'c') + vector = np.ones(6,'c') self.assertRaises(TypeError, zeros, vector) # Test the (int DIM1, type* INPLACE_ARRAY1) typemap @@ -378,7 +378,7 @@ if __name__ == "__main__": # Execute the test suite print "Testing 1D Functions of Module Vector" - print "NumPy version", N.__version__ + print "NumPy version", np.__version__ print result = unittest.TextTestRunner(verbosity=2).run(suite) sys.exit(len(result.errors) + len(result.failures)) diff --git a/numpy/lib/getlimits.py b/numpy/lib/getlimits.py index 00c3ea846..89b40203f 100644 --- a/numpy/lib/getlimits.py +++ b/numpy/lib/getlimits.py @@ -7,7 +7,7 @@ from machar import MachAr import numpy.core.numeric as numeric import numpy.core.numerictypes as ntypes from numpy.core.numeric import array -import numpy as N +import numpy as np def _frz(a): """fix rank-0 --> rank-1""" @@ -128,7 +128,7 @@ class iinfo: _max_vals = {} def __init__(self, type): - self.dtype = N.dtype(type) + self.dtype = np.dtype(type) self.kind = self.dtype.kind self.bits = self.dtype.itemsize * 8 self.key = "%s%d" % (self.kind, self.bits) diff --git a/numpy/lib/tests/test_getlimits.py b/numpy/lib/tests/test_getlimits.py index 3c53f3322..a85228689 100644 --- a/numpy/lib/tests/test_getlimits.py +++ b/numpy/lib/tests/test_getlimits.py @@ -2,12 +2,10 @@ """ from numpy.testing import * -set_package_path() import numpy.lib;reload(numpy.lib) from numpy.lib.getlimits import finfo, iinfo from numpy import single,double,longdouble -import numpy as N -restore_path() +import numpy as np ################################################## @@ -39,15 +37,15 @@ class TestIinfo(NumpyTestCase): def check_basic(self): dts = zip(['i1', 'i2', 'i4', 'i8', 'u1', 'u2', 'u4', 'u8'], - [N.int8, N.int16, N.int32, N.int64, - N.uint8, N.uint16, N.uint32, N.uint64]) + [np.int8, np.int16, np.int32, np.int64, + np.uint8, np.uint16, np.uint32, np.uint64]) for dt1, dt2 in dts: assert_equal(iinfo(dt1).min, iinfo(dt2).min) assert_equal(iinfo(dt1).max, iinfo(dt2).max) self.assertRaises(ValueError, iinfo, 'f4') def check_unsigned_max(self): - types = N.sctypes['uint'] + types = np.sctypes['uint'] for T in types: assert_equal(iinfo(T).max, T(-1)) diff --git a/numpy/lib/tests/test_polynomial.py b/numpy/lib/tests/test_polynomial.py index c9a230775..17d22e10e 100644 --- a/numpy/lib/tests/test_polynomial.py +++ b/numpy/lib/tests/test_polynomial.py @@ -74,22 +74,22 @@ poly1d([ 2.]) """ from numpy.testing import * -import numpy as N +import numpy as np class TestDocs(NumpyTestCase): def check_doctests(self): return self.rundocs() def check_roots(self): - assert_array_equal(N.roots([1,0,0]), [0,0]) + assert_array_equal(np.roots([1,0,0]), [0,0]) def check_str_leading_zeros(self): - p = N.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 = N.poly1d([1,2]) + p = np.poly1d([1,2]) p[0] = 0 p[1] = 0 assert_equal(str(p), " \n0") diff --git a/numpy/matlib.py b/numpy/matlib.py index cfc61f4f6..568169888 100644 --- a/numpy/matlib.py +++ b/numpy/matlib.py @@ -1,11 +1,10 @@ -from numpy.core.defmatrix import matrix, asmatrix +import numpy as np from numpy import ndarray, array -import numpy as N -from numpy import * +from numpy.core.defmatrix import matrix, asmatrix -__version__ = N.__version__ +__version__ = np.__version__ -__all__ = N.__all__[:] # copy numpy namespace +__all__ = np.__all__[:] # copy numpy namespace __all__ += ['rand', 'randn', 'repmat'] def empty(shape, dtype=None, order='C'): @@ -36,17 +35,17 @@ def identity(n,dtype=None): return b def eye(n,M=None, k=0, dtype=float): - return asmatrix(N.eye(n,M,k,dtype)) + return asmatrix(np.eye(n,M,k,dtype)) def rand(*args): if isinstance(args[0], tuple): args = args[0] - return asmatrix(N.random.rand(*args)) + return asmatrix(np.random.rand(*args)) def randn(*args): if isinstance(args[0], tuple): args = args[0] - return asmatrix(N.random.randn(*args)) + return asmatrix(np.random.randn(*args)) def repmat(a, m, n): """Repeat a 0-d to 2-d array mxn times diff --git a/numpy/oldnumeric/functions.py b/numpy/oldnumeric/functions.py index 1f09d8f84..5b2b1a8bf 100644 --- a/numpy/oldnumeric/functions.py +++ b/numpy/oldnumeric/functions.py @@ -1,6 +1,6 @@ # Functions that should behave the same as Numeric and need changing -import numpy as N +import numpy as np import numpy.core.multiarray as mu import numpy.core.numeric as nn from typeconv import convtypecode, convtypecode2 @@ -13,40 +13,40 @@ __all__ = ['take', 'repeat', 'sum', 'product', 'sometrue', 'alltrue', 'average'] def take(a, indicies, axis=0): - return N.take(a, indicies, axis) + return np.take(a, indicies, axis) def repeat(a, repeats, axis=0): - return N.repeat(a, repeats, axis) + return np.repeat(a, repeats, axis) def sum(x, axis=0): - return N.sum(x, axis) + return np.sum(x, axis) def product(x, axis=0): - return N.product(x, axis) + return np.product(x, axis) def sometrue(x, axis=0): - return N.sometrue(x, axis) + return np.sometrue(x, axis) def alltrue(x, axis=0): - return N.alltrue(x, axis) + return np.alltrue(x, axis) def cumsum(x, axis=0): - return N.cumsum(x, axis) + return np.cumsum(x, axis) def cumproduct(x, axis=0): - return N.cumproduct(x, axis) + return np.cumproduct(x, axis) def argmax(x, axis=-1): - return N.argmax(x, axis) + return np.argmax(x, axis) def argmin(x, axis=-1): - return N.argmin(x, axis) + return np.argmin(x, axis) def compress(condition, m, axis=-1): - return N.compress(condition, m, axis) + return np.compress(condition, m, axis) def fromfunction(args, dimensions): - return N.fromfunction(args, dimensions, dtype=int) + return np.fromfunction(args, dimensions, dtype=int) def ones(shape, typecode='l', savespace=0, dtype=None): """ones(shape, dtype=int) returns an array of the given @@ -87,14 +87,14 @@ def asarray(a, typecode=None, dtype=None): return mu.array(a, dtype, copy=0) def nonzero(a): - res = N.nonzero(a) + res = np.nonzero(a) if len(res) == 1: return res[0] else: raise ValueError, "Input argument must be 1d" def reshape(a, shape): - return N.reshape(a, shape) + return np.reshape(a, shape) def arange(start, stop=None, step=1, typecode=None, dtype=None): dtype = convtypecode2(typecode, dtype) @@ -105,20 +105,20 @@ def fromstring(string, typecode='l', count=-1, dtype=None): return mu.fromstring(string, dtype, count=count) def ravel(m): - return N.ravel(m) + return np.ravel(m) def trace(a, offset=0, axis1=0, axis2=1): - return N.trace(a, offset=0, axis1=0, axis2=1) + return np.trace(a, offset=0, axis1=0, axis2=1) def indices(dimensions, typecode=None, dtype=None): dtype = convtypecode(typecode, dtype) - return N.indices(dimensions, dtype) + return np.indices(dimensions, dtype) def where(condition, x, y): - return N.where(condition, x, y) + return np.where(condition, x, y) def cross_product(a, b, axis1=-1, axis2=-1): - return N.cross(a, b, axis1, axis2) + return np.cross(a, b, axis1, axis2) def average(a, axis=0, weights=None, returned=False): - return N.average(a, axis, weights, returned) + return np.average(a, axis, weights, returned) diff --git a/numpy/oldnumeric/typeconv.py b/numpy/oldnumeric/typeconv.py index 1fbf1e072..4e203d4ae 100644 --- a/numpy/oldnumeric/typeconv.py +++ b/numpy/oldnumeric/typeconv.py @@ -1,21 +1,21 @@ __all__ = ['oldtype2dtype', 'convtypecode', 'convtypecode2', 'oldtypecodes'] -import numpy as N - -oldtype2dtype = {'1': N.dtype(N.byte), - 's': N.dtype(N.short), -# 'i': N.dtype(N.intc), -# 'l': N.dtype(int), -# 'b': N.dtype(N.ubyte), - 'w': N.dtype(N.ushort), - 'u': N.dtype(N.uintc), -# 'f': N.dtype(N.single), -# 'd': N.dtype(float), -# 'F': N.dtype(N.csingle), -# 'D': N.dtype(complex), -# 'O': N.dtype(object), -# 'c': N.dtype('c'), - None:N.dtype(int) +import numpy as np + +oldtype2dtype = {'1': np.dtype(np.byte), + 's': np.dtype(np.short), +# 'i': np.dtype(np.intc), +# 'l': np.dtype(int), +# 'b': np.dtype(np.ubyte), + 'w': np.dtype(np.ushort), + 'u': np.dtype(np.uintc), +# 'f': np.dtype(np.single), +# 'd': np.dtype(float), +# 'F': np.dtype(np.csingle), +# 'D': np.dtype(complex), +# 'O': np.dtype(object), +# 'c': np.dtype('c'), + None: np.dtype(int) } # converts typecode=None to int @@ -24,7 +24,7 @@ def convtypecode(typecode, dtype=None): try: return oldtype2dtype[typecode] except: - return N.dtype(typecode) + return np.dtype(typecode) else: return dtype @@ -38,7 +38,7 @@ def convtypecode2(typecode, dtype=None): try: return oldtype2dtype[typecode] except: - return N.dtype(typecode) + return np.dtype(typecode) else: return dtype @@ -50,7 +50,7 @@ _changedtypes = {'B': 'b', class _oldtypecodes(dict): def __getitem__(self, obj): - char = N.dtype(obj).char + char = np.dtype(obj).char try: return _changedtypes[char] except KeyError: diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py index 633f6840f..898534742 100644 --- a/numpy/random/tests/test_random.py +++ b/numpy/random/tests/test_random.py @@ -1,6 +1,6 @@ from numpy.testing import * from numpy import random -import numpy as N +import numpy as np class TestMultinomial(NumpyTestCase): def test_basic(self): @@ -12,8 +12,8 @@ class TestMultinomial(NumpyTestCase): def test_int_negative_interval(self): assert -5 <= random.randint(-5,-1) < -1 x = random.randint(-5,-1,5) - assert N.all(-5 <= x) - assert N.all(x < -1) + assert np.all(-5 <= x) + assert np.all(x < -1) if __name__ == "__main__": NumpyTest().run() diff --git a/numpy/tests/test_ctypeslib.py b/numpy/tests/test_ctypeslib.py index 875e1a1c7..5558445b1 100644 --- a/numpy/tests/test_ctypeslib.py +++ b/numpy/tests/test_ctypeslib.py @@ -1,63 +1,61 @@ -from numpy.testing import * -set_package_path() -import numpy as N +import numpy as np from numpy.ctypeslib import ndpointer -restore_path() +from numpy.testing import * class TestNdpointer(NumpyTestCase): def check_dtype(self): - dt = N.intc + dt = np.intc p = ndpointer(dtype=dt) - self.assert_(p.from_param(N.array([1], dt))) + self.assert_(p.from_param(np.array([1], dt))) dt = '<i4' p = ndpointer(dtype=dt) - self.assert_(p.from_param(N.array([1], dt))) - dt = N.dtype('>i4') + self.assert_(p.from_param(np.array([1], dt))) + dt = np.dtype('>i4') p = ndpointer(dtype=dt) - p.from_param(N.array([1], dt)) + p.from_param(np.array([1], dt)) self.assertRaises(TypeError, p.from_param, - N.array([1], dt.newbyteorder('swap'))) + np.array([1], dt.newbyteorder('swap'))) dtnames = ['x', 'y'] - dtformats = [N.intc, N.float64] + dtformats = [np.intc, np.float64] dtdescr = {'names' : dtnames, 'formats' : dtformats} - dt = N.dtype(dtdescr) + dt = np.dtype(dtdescr) p = ndpointer(dtype=dt) - self.assert_(p.from_param(N.zeros((10,), dt))) - samedt = N.dtype(dtdescr) + self.assert_(p.from_param(np.zeros((10,), dt))) + samedt = np.dtype(dtdescr) p = ndpointer(dtype=samedt) - self.assert_(p.from_param(N.zeros((10,), dt))) - dt2 = N.dtype(dtdescr, align=True) + self.assert_(p.from_param(np.zeros((10,), dt))) + dt2 = np.dtype(dtdescr, align=True) if dt.itemsize != dt2.itemsize: - self.assertRaises(TypeError, p.from_param, N.zeros((10,), dt2)) + self.assertRaises(TypeError, p.from_param, np.zeros((10,), dt2)) else: - self.assert_(p.from_param(N.zeros((10,), dt2))) + self.assert_(p.from_param(np.zeros((10,), dt2))) def check_ndim(self): p = ndpointer(ndim=0) - self.assert_(p.from_param(N.array(1))) - self.assertRaises(TypeError, p.from_param, N.array([1])) + self.assert_(p.from_param(np.array(1))) + self.assertRaises(TypeError, p.from_param, np.array([1])) p = ndpointer(ndim=1) - self.assertRaises(TypeError, p.from_param, N.array(1)) - self.assert_(p.from_param(N.array([1]))) + self.assertRaises(TypeError, p.from_param, np.array(1)) + self.assert_(p.from_param(np.array([1]))) p = ndpointer(ndim=2) - self.assert_(p.from_param(N.array([[1]]))) + self.assert_(p.from_param(np.array([[1]]))) def check_shape(self): p = ndpointer(shape=(1,2)) - self.assert_(p.from_param(N.array([[1,2]]))) - self.assertRaises(TypeError, p.from_param, N.array([[1],[2]])) + self.assert_(p.from_param(np.array([[1,2]]))) + self.assertRaises(TypeError, p.from_param, np.array([[1],[2]])) p = ndpointer(shape=()) - self.assert_(p.from_param(N.array(1))) + self.assert_(p.from_param(np.array(1))) def check_flags(self): - x = N.array([[1,2,3]], order='F') + x = np.array([[1,2,3]], order='F') p = ndpointer(flags='FORTRAN') self.assert_(p.from_param(x)) p = ndpointer(flags='CONTIGUOUS') self.assertRaises(TypeError, p.from_param, x) p = ndpointer(flags=x.flags.num) self.assert_(p.from_param(x)) - self.assertRaises(TypeError, p.from_param, N.array([[1,2,3]])) + self.assertRaises(TypeError, p.from_param, np.array([[1,2,3]])) if __name__ == "__main__": NumpyTest().run() |