summaryrefslogtreecommitdiff
path: root/numpy/doc
diff options
context:
space:
mode:
authorPaul Ivanov <paul.ivanov@local>2009-12-28 20:49:52 +0000
committerPaul Ivanov <paul.ivanov@local>2009-12-28 20:49:52 +0000
commite4f233ecfedd2aafa258db2d3ae27e30604cc020 (patch)
tree6d32fbdd19b8dca00cd7cafd8df076bac55ddfd8 /numpy/doc
parent5ba01996a9ab2fdfb7c120a5afae801f854a781a (diff)
downloadnumpy-e4f233ecfedd2aafa258db2d3ae27e30604cc020.tar.gz
fixed a whole bunch of doctests
Diffstat (limited to 'numpy/doc')
-rw-r--r--numpy/doc/__init__.py2
-rw-r--r--numpy/doc/basics.py5
-rw-r--r--numpy/doc/constants.py16
-rw-r--r--numpy/doc/glossary.py15
-rw-r--r--numpy/doc/indexing.py18
-rw-r--r--numpy/doc/misc.py5
-rw-r--r--numpy/doc/structured_arrays.py3
-rw-r--r--numpy/doc/ufuncs.py2
8 files changed, 39 insertions, 27 deletions
diff --git a/numpy/doc/__init__.py b/numpy/doc/__init__.py
index 85c378182..6589b5492 100644
--- a/numpy/doc/__init__.py
+++ b/numpy/doc/__init__.py
@@ -20,7 +20,7 @@ The following topics are available:
You can view them by
->>> help(np.doc.TOPIC)
+>>> help(np.doc.TOPIC) #doctest: +SKIP
""" % '\n- '.join([''] + __all__)
diff --git a/numpy/doc/basics.py b/numpy/doc/basics.py
index d34c1f303..5e7291957 100644
--- a/numpy/doc/basics.py
+++ b/numpy/doc/basics.py
@@ -67,6 +67,7 @@ functions or methods accept. Some examples::
>>> y
array([1, 2, 4])
>>> z = np.arange(3, dtype=np.uint8)
+ >>> z
array([0, 1, 2], dtype=uint8)
Array types can also be referred to by character codes, mostly to retain
@@ -81,8 +82,8 @@ We recommend using dtype objects instead.
To convert the type of an array, use the .astype() method (preferred) or
the type itself as a function. For example: ::
- >>> z.astype(float)
- array([0., 1., 2.])
+ >>> z.astype(float) #doctest: +NORMALIZE_WHITESPACE
+ array([ 0., 1., 2.])
>>> np.int8(z)
array([0, 1, 2], dtype=int8)
diff --git a/numpy/doc/constants.py b/numpy/doc/constants.py
index a4487b72a..adb7c7e02 100644
--- a/numpy/doc/constants.py
+++ b/numpy/doc/constants.py
@@ -322,20 +322,20 @@ add_newdoc('numpy', 'newaxis',
Examples
--------
- >>> newaxis is None
+ >>> np.newaxis is None
True
>>> x = np.arange(3)
>>> x
array([0, 1, 2])
- >>> x[:, newaxis]
+ >>> x[:, np.newaxis]
array([[0],
[1],
[2]])
- >>> x[:, newaxis, newaxis]
+ >>> x[:, np.newaxis, np.newaxis]
array([[[0]],
[[1]],
[[2]]])
- >>> x[:, newaxis] * x
+ >>> x[:, np.newaxis] * x
array([[0, 0, 0],
[0, 1, 2],
[0, 2, 4]])
@@ -343,20 +343,20 @@ add_newdoc('numpy', 'newaxis',
Outer product, same as ``outer(x, y)``:
>>> y = np.arange(3, 6)
- >>> x[:, newaxis] * y
+ >>> x[:, np.newaxis] * y
array([[ 0, 0, 0],
[ 3, 4, 5],
[ 6, 8, 10]])
``x[newaxis, :]`` is equivalent to ``x[newaxis]`` and ``x[None]``:
- >>> x[newaxis, :].shape
+ >>> x[np.newaxis, :].shape
(1, 3)
- >>> x[newaxis].shape
+ >>> x[np.newaxis].shape
(1, 3)
>>> x[None].shape
(1, 3)
- >>> x[:, newaxis].shape
+ >>> x[:, np.newaxis].shape
(3, 1)
""")
diff --git a/numpy/doc/glossary.py b/numpy/doc/glossary.py
index f591a5424..dc7c75a0a 100644
--- a/numpy/doc/glossary.py
+++ b/numpy/doc/glossary.py
@@ -181,7 +181,7 @@ iterable
[1, 4, 9]
It is often used in combintion with ``enumerate``::
-
+ >>> keys = ['a','b','c']
>>> for n, k in enumerate(keys):
... print "Key %d: %s" % (n, k)
...
@@ -242,13 +242,16 @@ masked array
>>> x = np.ma.masked_array([np.nan, 2, np.nan], [True, False, True])
>>> x
masked_array(data = [-- 2.0 --],
- mask = [ True False True],
- fill_value=1e+20)
+ mask = [ True False True],
+ fill_value = 1e+20)
+ <BLANKLINE>
>>> x + [1, 2, 3]
masked_array(data = [-- 4.0 --],
- mask = [ True False True],
- fill_value=1e+20)
+ mask = [ True False True],
+ fill_value = 1e+20)
+ <BLANKLINE>
+
Masked arrays are often used when operating on arrays containing
missing or invalid entries.
@@ -366,7 +369,7 @@ tuple
This is often used when a function returns multiple values:
>>> def return_many():
- ... return 1, 'alpha'
+ ... return 1, 'alpha', None
>>> a, b, c = return_many()
>>> a, b, c
diff --git a/numpy/doc/indexing.py b/numpy/doc/indexing.py
index 365edd67a..282f35288 100644
--- a/numpy/doc/indexing.py
+++ b/numpy/doc/indexing.py
@@ -88,7 +88,7 @@ examples illustrates best: ::
>>> x[:-7]
array([0, 1, 2])
>>> x[1:7:2]
- array([1,3,5])
+ array([1, 3, 5])
>>> y = np.arange(35).reshape(5,7)
>>> y[1:5:2,::3]
array([[ 7, 10, 13],
@@ -294,6 +294,9 @@ remaining unspecified dimensions. For example: ::
This is equivalent to: ::
>>> z[1,:,:,2]
+ array([[29, 32, 35],
+ [38, 41, 44],
+ [47, 50, 53]])
Assigning values to indexed arrays
==================================
@@ -304,6 +307,7 @@ assigned to the indexed array must be shape consistent (the same shape
or broadcastable to the shape the index produces). For example, it is
permitted to assign a constant to a slice: ::
+ >>> x = np.arange(10)
>>> x[2:7] = 1
or an array of the right size: ::
@@ -327,7 +331,7 @@ assignments are always made to the original data in the array
actions may not work as one may naively expect. This particular
example is often surprising to people: ::
- >>> x[np.array([1, 1, 3, 1]) += 1
+ >>> x[np.array([1, 1, 3, 1])] += 1
Where people expect that the 1st location will be incremented by 3.
In fact, it will only be incremented by 1. The reason is because
@@ -360,6 +364,7 @@ Slices can be specified within programs by using the slice() function
in Python. For example: ::
>>> indices = (1,1,1,slice(0,2)) # same as [1,1,1,0:2]
+ >>> z[indices]
array([39, 40])
Likewise, ellipsis can be specified by code by using the Ellipsis object: ::
@@ -376,9 +381,10 @@ function directly as an index since it always returns a tuple of index arrays.
Because the special treatment of tuples, they are not automatically converted
to an array as a list would be. As an example: ::
- >>> z[[1,1,1,1]]
- ... # produces a large array
- >>> z[(1,1,1,1)]
- 40 # returns a single value
+ >>> z[[1,1,1,1]] # produces a large array
+ array([[[[27, 28, 29],
+ [30, 31, 32], ...
+ >>> z[(1,1,1,1)] # returns a single value
+ 40
"""
diff --git a/numpy/doc/misc.py b/numpy/doc/misc.py
index eb2dc4395..8575a8e4f 100644
--- a/numpy/doc/misc.py
+++ b/numpy/doc/misc.py
@@ -13,12 +13,12 @@ original value was)
Note: cannot use equality to test NaNs. E.g.: ::
+ >>> myarr = np.array([1., 0., np.nan, 3.])
>>> np.where(myarr == np.nan)
>>> nan == nan # is always False! Use special numpy functions instead.
>>> np.nan == np.nan
False
- >>> myarr = np.array([1., 0., np.nan, 3.])
>>> myarr[myarr == np.nan] = 0. # doesn't work
>>> myarr
array([ 1., 0., NaN, 3.])
@@ -68,7 +68,7 @@ These behaviors can be set for all kinds of errors or specific ones: ::
underflow: floating point underflows
Note that integer divide-by-zero is handled by the same machinery.
-These behaviors are set on a per-thead basis.
+These behaviors are set on a per-thread basis.
Examples:
------------
@@ -86,6 +86,7 @@ Examples:
>>> def errorhandler(errstr, errflag):
... print "saw stupid error!"
>>> np.seterrcall(errorhandler)
+<function err_handler at 0x...>
>>> j = np.seterr(all='call')
>>> np.zeros(5, dtype=np.int32)/0
FloatingPointError: invalid value encountered in divide
diff --git a/numpy/doc/structured_arrays.py b/numpy/doc/structured_arrays.py
index 59af4eb57..21fdf87ea 100644
--- a/numpy/doc/structured_arrays.py
+++ b/numpy/doc/structured_arrays.py
@@ -105,7 +105,7 @@ dtype definition (using any of the variants being described here). As
an example (using a definition using a list, so see 3) for further
details): ::
- >>> x = zeros(3, dtype=('i4',[('r','u1'), ('g','u1'), ('b','u1'), ('a','u1')]))
+ >>> x = np.zeros(3, dtype=('i4',[('r','u1'), ('g','u1'), ('b','u1'), ('a','u1')]))
>>> x
array([0, 0, 0])
>>> x['r']
@@ -145,6 +145,7 @@ The other dictionary form permitted is a dictionary of name keys with tuple
values specifying type, offset, and an optional title.
>>> x = np.zeros(3, dtype={'col1':('i1',0,'title 1'), 'col2':('f4',1,'title 2')})
+ >>> x
array([(0, 0.0), (0, 0.0), (0, 0.0)],
dtype=[(('title 1', 'col1'), '|i1'), (('title 2', 'col2'), '>f4')])
diff --git a/numpy/doc/ufuncs.py b/numpy/doc/ufuncs.py
index 4819e5268..d6a1cd62a 100644
--- a/numpy/doc/ufuncs.py
+++ b/numpy/doc/ufuncs.py
@@ -82,7 +82,7 @@ array. A couple examples: ::
>>> np.add.accumulate(np.arange(10))
array([ 0, 1, 3, 6, 10, 15, 21, 28, 36, 45])
- >>> np.multiply.accumulate(np.arange(1,9))
+ >>> np.multiply.accumulate(np.arange(1,9))
array([ 1, 2, 6, 24, 120, 720, 5040, 40320])
The behavior for multidimensional arrays is the same as for .reduce(), as is the use of the axis keyword).