diff options
author | Alan McIntyre <alan.mcintyre@local> | 2008-07-05 14:26:16 +0000 |
---|---|---|
committer | Alan McIntyre <alan.mcintyre@local> | 2008-07-05 14:26:16 +0000 |
commit | 36e02207c1a82fe669531dd24ec799eca2989c80 (patch) | |
tree | 104f800d6800c4a01a0aecac323a8a70517aa94b /numpy | |
parent | f07e385b69ee59ef6abe05f164138dc6a7279291 (diff) | |
download | numpy-36e02207c1a82fe669531dd24ec799eca2989c80.tar.gz |
Use the implicit "import numpy as np" made available to all doctests instead
of explicit imports or dependency on the local scope where the doctest is
defined..
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/add_newdocs.py | 76 | ||||
-rw-r--r-- | numpy/lib/financial.py | 8 | ||||
-rw-r--r-- | numpy/lib/function_base.py | 33 | ||||
-rw-r--r-- | numpy/lib/io.py | 6 | ||||
-rw-r--r-- | numpy/lib/polynomial.py | 4 | ||||
-rw-r--r-- | numpy/lib/scimath.py | 63 | ||||
-rw-r--r-- | numpy/lib/shape_base.py | 70 | ||||
-rw-r--r-- | numpy/lib/twodim_base.py | 8 | ||||
-rw-r--r-- | numpy/linalg/linalg.py | 75 | ||||
-rw-r--r-- | numpy/ma/core.py | 20 | ||||
-rw-r--r-- | numpy/ma/extras.py | 2 | ||||
-rw-r--r-- | numpy/testing/decorators.py | 1 |
12 files changed, 178 insertions, 188 deletions
diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py index c44ba9094..eb1083df7 100644 --- a/numpy/add_newdocs.py +++ b/numpy/add_newdocs.py @@ -19,46 +19,46 @@ Examples -------- Using array-scalar type: ->>> dtype(int16) +>>> np.dtype(np.int16) dtype('int16') Record, one field name 'f1', containing int16: ->>> dtype([('f1', int16)]) +>>> np.dtype([('f1', np.int16)]) dtype([('f1', '<i2')]) Record, one field named 'f1', in itself containing a record with one field: ->>> dtype([('f1', [('f1', int16)])]) +>>> np.dtype([('f1', [('f1', np.int16)])]) dtype([('f1', [('f1', '<i2')])]) Record, two fields: the first field contains an unsigned int, the second an int32: ->>> dtype([('f1', uint), ('f2', int32)]) +>>> np.dtype([('f1', np.uint), ('f2', np.int32)]) dtype([('f1', '<u4'), ('f2', '<i4')]) Using array-protocol type strings: ->>> dtype([('a','f8'),('b','S10')]) +>>> np.dtype([('a','f8'),('b','S10')]) dtype([('a', '<f8'), ('b', '|S10')]) Using comma-separated field formats. The shape is (2,3): ->>> dtype("i4, (2,3)f8") +>>> np.dtype("i4, (2,3)f8") dtype([('f0', '<i4'), ('f1', '<f8', (2, 3))]) Using tuples. ``int`` is a fixed type, 3 the field's shape. ``void`` is a flexible type, here of size 10: ->>> dtype([('hello',(int,3)),('world',void,10)]) +>>> np.dtype([('hello',(np.int,3)),('world',np.void,10)]) dtype([('hello', '<i4', 3), ('world', '|V10')]) Subdivide ``int16`` into 2 ``int8``'s, called x and y. 0 and 1 are the offsets in bytes: ->>> dtype((int16, {'x':(int8,0), 'y':(int8,1)})) +>>> np.dtype((np.int16, {'x':(np.int8,0), 'y':(np.int8,1)})) dtype(('<i2', [('x', '|i1'), ('y', '|i1')])) Using dictionaries. Two fields named 'gender' and 'age': ->>> dtype({'names':['gender','age'], 'formats':['S1',uint8]}) +>>> np.dtype({'names':['gender','age'], 'formats':['S1',np.uint8]}) dtype([('gender', '|S1'), ('age', '|u1')]) Offsets in bytes, here 0 and 25: ->>> dtype({'surname':('S25',0),'age':(uint8,25)}) +>>> np.dtype({'surname':('S25',0),'age':(np.uint8,25)}) dtype([('surname', '|S25'), ('age', '|u1')]) """) @@ -386,7 +386,7 @@ add_newdoc('numpy.core.multiarray','concatenate', Examples -------- - >>> concatenate( ([0,1,2], [5,6,7]) ) + >>> np.concatenate( ([0,1,2], [5,6,7]) ) array([0, 1, 2, 5, 6, 7]) """) @@ -480,7 +480,7 @@ add_newdoc('numpy.core.multiarray','where', Examples -------- - >>> where([True,False,True],[1,2,3],[4,5,6]) + >>> np.where([True,False,True],[1,2,3],[4,5,6]) array([1, 5, 3]) """) @@ -520,12 +520,12 @@ add_newdoc('numpy.core.multiarray','lexsort', -------- >>> a = [1,5,1,4,3,6,7] >>> b = [9,4,0,4,0,4,3] - >>> ind = lexsort((b,a)) + >>> ind = np.lexsort((b,a)) >>> print ind [2 0 4 3 1 5 6] - >>> print take(a,ind) + >>> print np.take(a,ind) [1 1 3 4 5 6 7] - >>> print take(b,ind) + >>> print np.take(b,ind) [0 9 0 4 4 4 3] """) @@ -858,7 +858,7 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('argmax', Examples -------- - >>> a = arange(6).reshape(2,3) + >>> a = np.arange(6).reshape(2,3) >>> a.argmax() 5 >>> a.argmax(0) @@ -889,7 +889,7 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('argmin', Examples -------- - >>> a = arange(6).reshape(2,3) + >>> a = np.arange(6).reshape(2,3) >>> a.argmin() 0 >>> a.argmin(0) @@ -1008,10 +1008,10 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('choose', -------- >>> choices = [[0, 1, 2, 3], [10, 11, 12, 13], ... [20, 21, 22, 23], [30, 31, 32, 33]] - >>> a = array([2, 3, 1, 0], dtype=int) + >>> a = np.array([2, 3, 1, 0], dtype=int) >>> a.choose(choices) array([20, 31, 12, 3]) - >>> a = array([2, 4, 1, 0], dtype=int) + >>> a = np.array([2, 4, 1, 0], dtype=int) >>> a.choose(choices, mode='clip') array([20, 31, 12, 3]) >>> a.choose(choices, mode='wrap') @@ -1226,7 +1226,7 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('diagonal', Examples -------- - >>> a = arange(4).reshape(2,2) + >>> a = np.arange(4).reshape(2,2) >>> a array([[0, 1], [2, 3]]) @@ -1235,7 +1235,7 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('diagonal', >>> a.diagonal(1) array([1]) - >>> a = arange(8).reshape(2,2,2) + >>> a = np.arange(8).reshape(2,2,2) >>> a array([[[0, 1], [2, 3]], @@ -1462,13 +1462,13 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('prod', Examples -------- - >>> prod([1.,2.]) + >>> np.prod([1.,2.]) 2.0 - >>> prod([1.,2.], dtype=int32) + >>> np.prod([1.,2.], dtype=np.int32) 2 - >>> prod([[1.,2.],[3.,4.]]) + >>> np.prod([[1.,2.],[3.,4.]]) 24.0 - >>> prod([[1.,2.],[3.,4.]], axis=1) + >>> np.prod([[1.,2.],[3.,4.]], axis=1) array([ 2., 12.]) Notes @@ -1599,7 +1599,7 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('ravel', Examples -------- - >>> x = array([[1,2,3],[4,5,6]]) + >>> x = np.array([[1,2,3],[4,5,6]]) >>> x array([[1, 2, 3], [4, 5, 6]]) @@ -1637,7 +1637,7 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('repeat', Examples -------- - >>> x = array([[1,2],[3,4]]) + >>> x = np.array([[1,2],[3,4]]) >>> x.repeat(2) array([1, 1, 2, 2, 3, 3, 4, 4]) >>> x.repeat(3, axis=1) @@ -1725,10 +1725,10 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('round', Examples -------- - >>> x = array([.5, 1.5, 2.5, 3.5, 4.5]) + >>> x = np.array([.5, 1.5, 2.5, 3.5, 4.5]) >>> x.round() array([ 0., 2., 2., 4., 4.]) - >>> x = array([1,2,3,11]) + >>> x = np.array([1,2,3,11]) >>> x.round(decimals=1) array([ 1, 2, 3, 11]) >>> x.round(decimals=-1) @@ -1840,7 +1840,7 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('squeeze', Examples -------- - >>> x = array([[[1,1,1],[2,2,2],[3,3,3]]]) + >>> x = np.array([[[1,1,1],[2,2,2],[3,3,3]]]) >>> x.shape (1, 3, 3) >>> x.squeeze().shape @@ -1929,15 +1929,15 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('sum', Examples -------- - >>> array([0.5, 1.5]).sum() + >>> np.array([0.5, 1.5]).sum() 2.0 - >>> array([0.5, 1.5]).sum(dtype=int32) + >>> np.array([0.5, 1.5]).sum(dtype=np.int32) 1 - >>> array([[0, 1], [0, 5]]).sum(axis=0) + >>> np.array([[0, 1], [0, 5]]).sum(axis=0) array([0, 6]) - >>> array([[0, 1], [0, 5]]).sum(axis=1) + >>> np.array([[0, 1], [0, 5]]).sum(axis=1) array([1, 5]) - >>> ones(128, dtype=int8).sum(dtype=int8) # overflow! + >>> np.ones(128, dtype=np.int8).sum(dtype=np.int8) # overflow! -128 Notes @@ -2120,9 +2120,9 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('trace', Examples -------- - >>> eye(3).trace() + >>> np.eye(3).trace() 3.0 - >>> a = arange(8).reshape((2,2,2)) + >>> a = np.arange(8).reshape((2,2,2)) >>> a.trace() array([6, 8]) @@ -2139,7 +2139,7 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('transpose', Examples -------- - >>> a = array([[1,2],[3,4]]) + >>> a = np.array([[1,2],[3,4]]) >>> a array([[1, 2], [3, 4]]) diff --git a/numpy/lib/financial.py b/numpy/lib/financial.py index a3552ebc0..9c5d2753a 100644 --- a/numpy/lib/financial.py +++ b/numpy/lib/financial.py @@ -69,7 +69,7 @@ What is the future value after 10 years of saving $100 now, with an additional monthly savings of $100. Assume the interest rate is 5% (annually) compounded monthly? ->>> fv(0.05/12, 10*12, -100, -100) +>>> np.fv(0.05/12, 10*12, -100, -100) 15692.928894335748 By convention, the negative sign represents cash flow out (i.e. money not @@ -94,7 +94,7 @@ Examples What would the monthly payment need to be to pay off a $200,000 loan in 15 years at an annual interest rate of 7.5%? ->>> pmt(0.075/12, 12*15, 200000) +>>> np.pmt(0.075/12, 12*15, 200000) -1854.0247200054619 In order to pay-off (i.e. have a future-value of 0) the $200,000 obtained @@ -122,7 +122,7 @@ Examples If you only had $150 to spend as payment, how long would it take to pay-off a loan of $8,000 at 7% annual interest? ->>> nper(0.07/12, -150, 8000) +>>> np.nper(0.07/12, -150, 8000) 64.073348770661852 So, over 64 months would be required to pay off the loan. @@ -130,7 +130,7 @@ So, over 64 months would be required to pay off the loan. The same analysis could be done with several different interest rates and/or payments and/or total amounts to produce an entire table. ->>> nper(*(ogrid[0.06/12:0.071/12:0.01/12, -200:-99:100, 6000:7001:1000])) +>>> np.nper(*(np.ogrid[0.06/12:0.071/12:0.01/12, -200:-99:100, 6000:7001:1000])) array([[[ 32.58497782, 38.57048452], [ 71.51317802, 86.37179563]], diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index fe6e67903..e8df0b439 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -471,7 +471,7 @@ def average(a, axis=None, weights=None, returned=False): Examples -------- - >>> average(range(1,11), weights=range(10,0,-1)) + >>> np.average(range(1,11), weights=range(10,0,-1)) 4.0 Raises @@ -893,7 +893,7 @@ def trim_zeros(filt, trim='fb'): Examples -------- - >>> a = array((0, 0, 0, 1, 2, 3, 2, 1, 0)) + >>> a = np.array((0, 0, 0, 1, 2, 3, 2, 1, 0)) >>> np.trim_zeros(a) array([1, 2, 3, 2, 1]) @@ -1069,7 +1069,7 @@ class vectorize(object): ... else: ... return a+b - >>> vfunc = vectorize(myfunc) + >>> vfunc = np.vectorize(myfunc) >>> vfunc([1, 2, 3, 4], 2) array([3, 4, 1, 2]) @@ -1486,29 +1486,28 @@ def median(a, axis=0, out=None, overwrite_input=False): Examples -------- - >>> from numpy import median >>> a = np.array([[10, 7, 4], [3, 2, 1]]) >>> a array([[10, 7, 4], [ 3, 2, 1]]) - >>> median(a) + >>> np.median(a) array([ 6.5, 4.5, 2.5]) - >>> median(a, axis=None) + >>> np.median(a, axis=None) 3.5 - >>> median(a, axis=1) + >>> np.median(a, axis=1) array([ 7., 2.]) - >>> m = median(a) + >>> m = np.median(a) >>> out = np.zeros_like(m) - >>> median(a, out=m) + >>> np.median(a, out=m) array([ 6.5, 4.5, 2.5]) >>> m array([ 6.5, 4.5, 2.5]) >>> b = a.copy() - >>> median(b, axis=1, overwrite_input=True) + >>> np.median(b, axis=1, overwrite_input=True) array([ 7., 2.]) >>> assert not np.all(a==b) >>> b = a.copy() - >>> median(b, axis=None, overwrite_input=True) + >>> np.median(b, axis=None, overwrite_input=True) 3.5 >>> assert not np.all(a==b) """ @@ -1632,11 +1631,11 @@ def delete(arr, obj, axis=None): ... [1,2,3], ... [6,7,8]] - >>> delete(arr, 1, 1) + >>> np.delete(arr, 1, 1) array([[3, 5], [1, 3], [6, 8]]) - >>> delete(arr, 1, 0) + >>> np.delete(arr, 1, 0) array([[3, 4, 5], [6, 7, 8]]) """ @@ -1732,11 +1731,11 @@ def insert(arr, obj, values, axis=None): Examples -------- - >>> a = array([[1,2,3], - ... [4,5,6], - ... [7,8,9]]) + >>> a = np.array([[1,2,3], + ... [4,5,6], + ... [7,8,9]]) - >>> insert(a, [1,2], [[4],[5]], axis=0) + >>> np.insert(a, [1,2], [[4],[5]], axis=0) array([[1, 2, 3], [4, 4, 4], [4, 5, 6], diff --git a/numpy/lib/io.py b/numpy/lib/io.py index db4e73358..36723f1d8 100644 --- a/numpy/lib/io.py +++ b/numpy/lib/io.py @@ -344,9 +344,9 @@ def savetxt(fname, X, fmt='%.18e',delimiter=' '): Examples -------- - >>> savetxt('test.out', x, delimiter=',') # X is an array - >>> savetxt('test.out', (x,y,z)) # x,y,z equal sized 1D arrays - >>> savetxt('test.out', x, fmt='%1.4e') # use exponential notation + >>> np.savetxt('test.out', x, delimiter=',') # X is an array + >>> np.savetxt('test.out', (x,y,z)) # x,y,z equal sized 1D arrays + >>> np.savetxt('test.out', x, fmt='%1.4e') # use exponential notation Notes on fmt ------------ diff --git a/numpy/lib/polynomial.py b/numpy/lib/polynomial.py index 303cdb13c..8fb0337dc 100644 --- a/numpy/lib/polynomial.py +++ b/numpy/lib/polynomial.py @@ -52,8 +52,8 @@ def poly(seq_of_zeros): Example: - >>> b = roots([1,3,1,5,6]) - >>> poly(b) + >>> b = np.roots([1,3,1,5,6]) + >>> np.poly(b) array([ 1., 3., 1., 5., 6.]) """ diff --git a/numpy/lib/scimath.py b/numpy/lib/scimath.py index d3965668d..2a951135a 100644 --- a/numpy/lib/scimath.py +++ b/numpy/lib/scimath.py @@ -50,8 +50,8 @@ def _tocomplex(arr): >>> a = np.array([1,2,3],np.short) - >>> ac = _tocomplex(a); ac - array([ 1.+0.j, 2.+0.j, 3.+0.j], dtype=complex64) + >>> ac = np.lib.scimath._tocomplex(a); ac + array([ 1.+0.j, 2.+0.j, 3.+0.j], dtype=np.complex64) >>> ac.dtype dtype('complex64') @@ -61,7 +61,7 @@ def _tocomplex(arr): >>> b = np.array([1,2,3],np.double) - >>> bc = _tocomplex(b); bc + >>> bc = np.lib.scimath._tocomplex(b); bc array([ 1.+0.j, 2.+0.j, 3.+0.j]) >>> bc.dtype @@ -72,7 +72,7 @@ def _tocomplex(arr): >>> c = np.array([1,2,3],np.csingle) - >>> cc = _tocomplex(c); cc + >>> cc = np.lib.scimath._tocomplex(c); cc array([ 1.+0.j, 2.+0.j, 3.+0.j], dtype=complex64) >>> c *= 2; c @@ -102,10 +102,10 @@ def _fix_real_lt_zero(x): Examples -------- - >>> _fix_real_lt_zero([1,2]) + >>> np.lib.scimath._fix_real_lt_zero([1,2]) array([1, 2]) - >>> _fix_real_lt_zero([-1,2]) + >>> np.lib.scimath._fix_real_lt_zero([-1,2]) array([-1.+0.j, 2.+0.j]) """ x = asarray(x) @@ -128,10 +128,10 @@ def _fix_int_lt_zero(x): Examples -------- - >>> _fix_int_lt_zero([1,2]) + >>> np.lib.scimath._fix_int_lt_zero([1,2]) array([1, 2]) - >>> _fix_int_lt_zero([-1,2]) + >>> np.lib.scimath._fix_int_lt_zero([-1,2]) array([-1., 2.]) """ x = asarray(x) @@ -154,10 +154,10 @@ def _fix_real_abs_gt_1(x): Examples -------- - >>> _fix_real_abs_gt_1([0,1]) + >>> np.lib.scimath._fix_real_abs_gt_1([0,1]) array([0, 1]) - >>> _fix_real_abs_gt_1([0,2]) + >>> np.lib.scimath._fix_real_abs_gt_1([0,2]) array([ 0.+0.j, 2.+0.j]) """ x = asarray(x) @@ -180,17 +180,17 @@ def sqrt(x): -------- For real, non-negative inputs this works just like numpy.sqrt(): - >>> sqrt(1) + >>> np.lib.scimath.sqrt(1) 1.0 - >>> sqrt([1,4]) + >>> np.lib.scimath.sqrt([1,4]) array([ 1., 2.]) But it automatically handles negative inputs: - >>> sqrt(-1) + >>> np.lib.scimath.sqrt(-1) (0.0+1.0j) - >>> sqrt([-1,4]) + >>> np.lib.scimath.sqrt([-1,4]) array([ 0.+1.j, 2.+0.j]) """ x = _fix_real_lt_zero(x) @@ -213,14 +213,13 @@ def log(x): Examples -------- >>> import math - - >>> log(math.exp(1)) + >>> np.lib.scimath.log(math.exp(1)) 1.0 Negative arguments are correctly handled (recall that for negative arguments, the identity exp(log(z))==z does not hold anymore): - >>> log(-math.exp(1)) == (1+1j*math.pi) + >>> np.lib.scimath.log(-math.exp(1)) == (1+1j*math.pi) True """ x = _fix_real_lt_zero(x) @@ -246,11 +245,11 @@ def log10(x): (We set the printing precision so the example can be auto-tested) >>> np.set_printoptions(precision=4) - >>> log10([10**1,10**2]) + >>> np.lib.scimath.log10([10**1,10**2]) array([ 1., 2.]) - >>> log10([-10**1,-10**2,10**2]) + >>> np.lib.scimath.log10([-10**1,-10**2,10**2]) array([ 1.+1.3644j, 2.+1.3644j, 2.+0.j ]) """ x = _fix_real_lt_zero(x) @@ -276,10 +275,10 @@ def logn(n, x): (We set the printing precision so the example can be auto-tested) >>> np.set_printoptions(precision=4) - >>> logn(2,[4,8]) + >>> np.lib.scimath.logn(2,[4,8]) array([ 2., 3.]) - >>> logn(2,[-4,-8,8]) + >>> np.lib.scimath.logn(2,[-4,-8,8]) array([ 2.+4.5324j, 3.+4.5324j, 3.+0.j ]) """ x = _fix_real_lt_zero(x) @@ -306,10 +305,10 @@ def log2(x): (We set the printing precision so the example can be auto-tested) >>> np.set_printoptions(precision=4) - >>> log2([4,8]) + >>> np.lib.scimath.log2([4,8]) array([ 2., 3.]) - >>> log2([-4,-8,8]) + >>> np.lib.scimath.log2([-4,-8,8]) array([ 2.+4.5324j, 3.+4.5324j, 3.+0.j ]) """ x = _fix_real_lt_zero(x) @@ -336,13 +335,13 @@ def power(x, p): (We set the printing precision so the example can be auto-tested) >>> np.set_printoptions(precision=4) - >>> power([2,4],2) + >>> np.lib.scimath.power([2,4],2) array([ 4, 16]) - >>> power([2,4],-2) + >>> np.lib.scimath.power([2,4],-2) array([ 0.25 , 0.0625]) - >>> power([-2,4],2) + >>> np.lib.scimath.power([-2,4],2) array([ 4.+0.j, 16.+0.j]) """ x = _fix_real_lt_zero(x) @@ -368,10 +367,10 @@ def arccos(x): -------- >>> np.set_printoptions(precision=4) - >>> arccos(1) + >>> np.lib.scimath.arccos(1) 0.0 - >>> arccos([1,2]) + >>> np.lib.scimath.arccos([1,2]) array([ 0.-0.j , 0.+1.317j]) """ x = _fix_real_abs_gt_1(x) @@ -397,10 +396,10 @@ def arcsin(x): (We set the printing precision so the example can be auto-tested) >>> np.set_printoptions(precision=4) - >>> arcsin(0) + >>> np.lib.scimath.arcsin(0) 0.0 - >>> arcsin([0,1]) + >>> np.lib.scimath.arcsin([0,1]) array([ 0. , 1.5708]) """ x = _fix_real_abs_gt_1(x) @@ -426,10 +425,10 @@ def arctanh(x): (We set the printing precision so the example can be auto-tested) >>> np.set_printoptions(precision=4) - >>> arctanh(0) + >>> np.lib.scimath.arctanh(0) 0.0 - >>> arctanh([0,2]) + >>> np.lib.scimath.arctanh([0,2]) array([ 0.0000+0.j , 0.5493-1.5708j]) """ x = _fix_real_abs_gt_1(x) diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py index 77f158eb3..afdb879e4 100644 --- a/numpy/lib/shape_base.py +++ b/numpy/lib/shape_base.py @@ -192,13 +192,13 @@ def vstack(tup): tup -- sequence of arrays. All arrays must have the same shape. Examples: - >>> a = array((1,2,3)) - >>> b = array((2,3,4)) + >>> a = np.array((1,2,3)) + >>> b = np.array((2,3,4)) >>> np.vstack((a,b)) array([[1, 2, 3], [2, 3, 4]]) - >>> a = array([[1],[2],[3]]) - >>> b = array([[2],[3],[4]]) + >>> a = np.array([[1],[2],[3]]) + >>> b = np.array([[2],[3],[4]]) >>> np.vstack((a,b)) array([[1], [2], @@ -222,14 +222,13 @@ def hstack(tup): tup -- sequence of arrays. All arrays must have the same shape. Examples: - >>> import numpy - >>> a = array((1,2,3)) - >>> b = array((2,3,4)) - >>> numpy.hstack((a,b)) + >>> a = np.array((1,2,3)) + >>> b = np.array((2,3,4)) + >>> np.hstack((a,b)) array([1, 2, 3, 2, 3, 4]) - >>> a = array([[1],[2],[3]]) - >>> b = array([[2],[3],[4]]) - >>> numpy.hstack((a,b)) + >>> a = np.array([[1],[2],[3]]) + >>> b = np.array([[2],[3],[4]]) + >>> np.hstack((a,b)) array([[1, 2], [2, 3], [3, 4]]) @@ -253,10 +252,9 @@ def column_stack(tup): tup -- sequence of 1D or 2D arrays. All arrays must have the same first dimension. Examples: - >>> import numpy - >>> a = array((1,2,3)) - >>> b = array((2,3,4)) - >>> numpy.column_stack((a,b)) + >>> a = np.array((1,2,3)) + >>> b = np.array((2,3,4)) + >>> np.column_stack((a,b)) array([[1, 2], [2, 3], [3, 4]]) @@ -283,16 +281,15 @@ def dstack(tup): tup -- sequence of arrays. All arrays must have the same shape. Examples: - >>> import numpy - >>> a = array((1,2,3)) - >>> b = array((2,3,4)) - >>> numpy.dstack((a,b)) + >>> a = np.array((1,2,3)) + >>> b = np.array((2,3,4)) + >>> np.dstack((a,b)) array([[[1, 2], [2, 3], [3, 4]]]) - >>> a = array([[1],[2],[3]]) - >>> b = array([[2],[3],[4]]) - >>> numpy.dstack((a,b)) + >>> a = np.array([[1],[2],[3]]) + >>> b = np.array([[2],[3],[4]]) + >>> np.dstack((a,b)) array([[[1, 2]], <BLANKLINE> [[2, 3]], @@ -432,12 +429,11 @@ def hsplit(ary,indices_or_sections): Related: hstack, split, array_split, vsplit, dsplit. Examples: - >>> import numpy - >>> a= array((1,2,3,4)) - >>> numpy.hsplit(a,2) + >>> a= np.array((1,2,3,4)) + >>> np.hsplit(a,2) [array([1, 2]), array([3, 4])] - >>> a = array([[1,2,3,4],[1,2,3,4]]) - >>> hsplit(a,2) + >>> a = np.array([[1,2,3,4],[1,2,3,4]]) + >>> np.hsplit(a,2) [array([[1, 2], [1, 2]]), array([[3, 4], [3, 4]])] @@ -482,9 +478,9 @@ def vsplit(ary,indices_or_sections): vstack, split, array_split, hsplit, dsplit. Examples: import numpy - >>> a = array([[1,2,3,4], - ... [1,2,3,4]]) - >>> numpy.vsplit(a,2) + >>> a = np.array([[1,2,3,4], + ... [1,2,3,4]]) + >>> np.vsplit(a,2) [array([[1, 2, 3, 4]]), array([[1, 2, 3, 4]])] """ @@ -519,8 +515,8 @@ def dsplit(ary,indices_or_sections): Related: dstack, split, array_split, hsplit, vsplit. Examples: - >>> a = array([[[1,2,3,4],[1,2,3,4]]]) - >>> dsplit(a,2) + >>> a = np.array([[[1,2,3,4],[1,2,3,4]]]) + >>> np.dsplit(a,2) [array([[[1, 2], [1, 2]]]), array([[[3, 4], [3, 4]]])] @@ -596,15 +592,15 @@ def tile(A, reps): Examples: - >>> a = array([0,1,2]) - >>> tile(a,2) + >>> a = np.array([0,1,2]) + >>> np.tile(a,2) array([0, 1, 2, 0, 1, 2]) - >>> tile(a,(1,2)) + >>> np.tile(a,(1,2)) array([[0, 1, 2, 0, 1, 2]]) - >>> tile(a,(2,2)) + >>> np.tile(a,(2,2)) array([[0, 1, 2, 0, 1, 2], [0, 1, 2, 0, 1, 2]]) - >>> tile(a,(2,1,2)) + >>> np.tile(a,(2,1,2)) array([[[0, 1, 2, 0, 1, 2]], <BLANKLINE> [[0, 1, 2, 0, 1, 2]]]) diff --git a/numpy/lib/twodim_base.py b/numpy/lib/twodim_base.py index 44082521c..ab1e5fcf0 100644 --- a/numpy/lib/twodim_base.py +++ b/numpy/lib/twodim_base.py @@ -88,13 +88,13 @@ def diagflat(v,k=0): Examples -------- - >>> diagflat([[1,2],[3,4]]]) + >>> np.diagflat([[1,2],[3,4]]) array([[1, 0, 0, 0], [0, 2, 0, 0], [0, 0, 3, 0], [0, 0, 0, 4]]) - >>> diagflat([1,2], 1) + >>> np.diagflat([1,2], 1) array([[0, 1, 0], [0, 0, 2], [0, 0, 0]]) @@ -180,8 +180,8 @@ def histogram2d(x,y, bins=10, range=None, normed=False, weights=None): - `xedges, yedges` : Arrays defining the bin edges. Example: - >>> x = random.randn(100,2) - >>> hist2d, xedges, yedges = histogram2d(x, bins = (6, 7)) + >>> x = np.random.randn(100,2) + >>> hist2d, xedges, yedges = np.lib.histogram2d(x, bins = (6, 7)) :SeeAlso: histogramdd """ diff --git a/numpy/linalg/linalg.py b/numpy/linalg/linalg.py index 4231bae51..1f28967e3 100644 --- a/numpy/linalg/linalg.py +++ b/numpy/linalg/linalg.py @@ -163,18 +163,17 @@ def tensorsolve(a, b, axes=None): Examples -------- - >>> from numpy import * - >>> a = eye(2*3*4) + >>> a = np.eye(2*3*4) >>> a.shape = (2*3,4, 2,3,4) - >>> b = random.randn(2*3,4) - >>> x = linalg.tensorsolve(a, b) + >>> b = np.random.randn(2*3,4) + >>> x = np.linalg.tensorsolve(a, b) >>> x.shape (2, 3, 4) - >>> allclose(tensordot(a, x, axes=3), b) + >>> np.allclose(np.tensordot(a, x, axes=3), b) True """ - a = asarray(a) + a,wrap = _makearray(a) b = asarray(b) an = a.ndim @@ -266,23 +265,22 @@ def tensorinv(a, ind=2): Examples -------- - >>> from numpy import * - >>> a = eye(4*6) + >>> a = np.eye(4*6) >>> a.shape = (4,6,8,3) - >>> ainv = linalg.tensorinv(a, ind=2) + >>> ainv = np.linalg.tensorinv(a, ind=2) >>> ainv.shape (8, 3, 4, 6) - >>> b = random.randn(4,6) - >>> allclose(tensordot(ainv, b), linalg.tensorsolve(a, b)) + >>> b = np.random.randn(4,6) + >>> np.allclose(np.tensordot(ainv, b), np.linalg.tensorsolve(a, b)) True - >>> a = eye(4*6) + >>> a = np.eye(4*6) >>> a.shape = (24,8,3) - >>> ainv = linalg.tensorinv(a, ind=1) + >>> ainv = np.linalg.tensorinv(a, ind=1) >>> ainv.shape (8, 3, 24) - >>> b = random.randn(24) - >>> allclose(tensordot(ainv, b, 1), linalg.tensorsolve(a, b)) + >>> b = np.random.randn(24) + >>> np.allclose(np.tensordot(ainv, b, 1), np.linalg.tensorsolve(a, b)) True """ a = asarray(a) @@ -318,12 +316,11 @@ def inv(a): Examples -------- - >>> from numpy import array, inv, dot - >>> a = array([[1., 2.], [3., 4.]]) - >>> inv(a) + >>> a = np.array([[1., 2.], [3., 4.]]) + >>> np.linalg.inv(a) array([[-2. , 1. ], [ 1.5, -0.5]]) - >>> dot(a, inv(a)) + >>> np.dot(a, np.linalg.inv(a)) array([[ 1., 0.], [ 0., 1.]]) @@ -360,7 +357,7 @@ def cholesky(a): >>> L array([[ 1.+0.j, 0.+0.j], [ 0.+2.j, 1.+0.j]]) - >>> dot(L, L.T.conj()) + >>> np.dot(L, L.T.conj()) array([[ 1.+0.j, 0.-2.j], [ 0.+2.j, 5.+0.j]]) @@ -427,16 +424,15 @@ def qr(a, mode='full'): Examples -------- - >>> from numpy import * - >>> a = random.randn(9, 6) - >>> q, r = linalg.qr(a) - >>> allclose(a, dot(q, r)) + >>> a = np.random.randn(9, 6) + >>> q, r = np.linalg.qr(a) + >>> np.allclose(a, np.dot(q, r)) True - >>> r2 = linalg.qr(a, mode='r') - >>> r3 = linalg.qr(a, mode='economic') - >>> allclose(r, r2) + >>> r2 = np.linalg.qr(a, mode='r') + >>> r3 = np.linalg.qr(a, mode='economic') + >>> np.allclose(r, r2) True - >>> allclose(r, triu(r3[:6,:6], k=0)) + >>> np.allclose(r, np.triu(r3[:6,:6], k=0)) True """ @@ -909,20 +905,20 @@ def svd(a, full_matrices=1, compute_uv=1): Examples -------- - >>> a = random.randn(9, 6) + 1j*random.randn(9, 6) - >>> U, s, Vh = linalg.svd(a) + >>> a = np.random.randn(9, 6) + 1j*np.random.randn(9, 6) + >>> U, s, Vh = np.linalg.svd(a) >>> U.shape, Vh.shape, s.shape ((9, 9), (6, 6), (6,)) - >>> U, s, Vh = linalg.svd(a, full_matrices=False) + >>> U, s, Vh = np.linalg.svd(a, full_matrices=False) >>> U.shape, Vh.shape, s.shape ((9, 6), (6, 6), (6,)) - >>> S = diag(s) - >>> allclose(a, dot(U, dot(S, Vh))) + >>> S = np.diag(s) + >>> np.allclose(a, np.dot(U, np.dot(S, Vh))) True - >>> s2 = linalg.svd(a, compute_uv=False) - >>> allclose(s, s2) + >>> s2 = np.linalg.svd(a, compute_uv=False) + >>> np.allclose(s, s2) True """ a, wrap = _makearray(a) @@ -1048,12 +1044,11 @@ def pinv(a, rcond=1e-15 ): Examples -------- - >>> from numpy import * - >>> a = random.randn(9, 6) - >>> B = linalg.pinv(a) - >>> allclose(a, dot(a, dot(B, a))) + >>> a = np.random.randn(9, 6) + >>> B = np.linalg.pinv(a) + >>> np.allclose(a, np.dot(a, np.dot(B, a))) True - >>> allclose(B, dot(B, dot(a, B))) + >>> np.allclose(B, np.dot(B, np.dot(a, B))) True """ diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 368abd11d..21c2f44d4 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -1694,7 +1694,7 @@ class MaskedArray(ndarray): Examples -------- - >>> x = array([1,2,3,4,5], mask=[0,0,1,0,1], fill_value=-999) + >>> x = np.ma.array([1,2,3,4,5], mask=[0,0,1,0,1], fill_value=-999) >>> x.filled() array([1,2,-999,4,-999]) >>> type(x.filled()) @@ -2116,10 +2116,10 @@ masked_%(name)s(data = %(data)s, Example ------- - >>> array([1,2,3]).all() + >>> np.ma.array([1,2,3]).all() True - >>> a = array([1,2,3], mask=True) - >>> (a.all() is masked) + >>> a = np.ma.array([1,2,3], mask=True) + >>> (a.all() is np.ma.masked) True """ @@ -2293,7 +2293,7 @@ masked_%(name)s(data = %(data)s, Example ------- - >>> print array(arange(10),mask=[0,0,0,1,1,1,0,0,0,0]).cumsum() + >>> print np.ma.array(np.arange(10), mask=[0,0,0,1,1,1,0,0,0,0]).cumsum() [0 1 3 -- -- -- 9 16 24 33] @@ -2348,13 +2348,13 @@ masked_%(name)s(data = %(data)s, Examples -------- - >>> prod([1.,2.]) + >>> np.prod([1.,2.]) 2.0 - >>> prod([1.,2.], dtype=int32) + >>> np.prod([1.,2.], dtype=np.int32) 2 - >>> prod([[1.,2.],[3.,4.]]) + >>> np.prod([[1.,2.],[3.,4.]]) 24.0 - >>> prod([[1.,2.],[3.,4.]], axis=1) + >>> np.prod([[1.,2.],[3.,4.]], axis=1) array([ 2., 12.]) Notes @@ -2755,7 +2755,7 @@ masked_%(name)s(data = %(data)s, Examples -------- - >>> a = arange(6).reshape(2,3) + >>> a = np.arange(6).reshape(2,3) >>> a.argmax() 5 >>> a.argmax(0) diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py index f369180f2..ab24d41c0 100644 --- a/numpy/ma/extras.py +++ b/numpy/ma/extras.py @@ -716,7 +716,7 @@ class mr_class(MAxisConcatenator): """Translate slice objects to concatenation along the first axis. For example: - >>> mr_[array([1,2,3]), 0, 0, array([4,5,6])] + >>> np.ma.mr_[np.ma.array([1,2,3]), 0, 0, np.ma.array([4,5,6])] array([1, 2, 3, 0, 0, 4, 5, 6]) """ diff --git a/numpy/testing/decorators.py b/numpy/testing/decorators.py index 1c86a8d55..dd9783e2f 100644 --- a/numpy/testing/decorators.py +++ b/numpy/testing/decorators.py @@ -30,6 +30,7 @@ def setastest(tf=True): If True specifies this is a test, not a test otherwise e.g + >>> from numpy.testing.decorators import setastest >>> @setastest(False) ... def func_with_test_in_name(arg1, arg2): pass ... |