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/lib | |
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/lib')
-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 |
7 files changed, 93 insertions, 99 deletions
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 """ |